辣鸡UVA不给数据也不给评测状态无限WA求助
查看原帖
辣鸡UVA不给数据也不给评测状态无限WA求助
226485
柳苏明楼主2020/8/31 16:05

rt,在UVA上交到无语。一直WA,在uDebug上也没找出错。求dalao帮助

#include <cstdio>
#include <cctype>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>

namespace quick {
#define tp template<typename Type>
	namespace in {
		inline char getc() {
			static char buf[1<<21],*p1=buf,*p2=buf;
			return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
		}
		inline int read(char *s) {
			*s=getc();
			while(isspace(*s)) {*s=getc();if(*s==EOF) return 0;}
			while(!isspace(*s)&&*s!=EOF) {s++;*s=getc();}
			*s='\0'; return 1;
		}
		tp inline int read(Type &x) {
			x=0;bool k=false;char c=getc();
			while(!isdigit(c)) {k|=(c=='-');c=getc();if(c==EOF) return 0;}
			while(isdigit(c)) {x=(x<<1)+(x<<3)+(c^48);c=getc();}
			x*=(k?-1:1); return 1;
		}
		template <typename Type,typename... Args>
		inline int read(Type &t,Args &...args) {
			int res=0;
			res+=read(t);res+=read(args...);
			return res;
		}
	}
	using in::read;
	namespace out {
		char buf[1<<21];int p1=-1;const int p2=(1<<21)-1;
		inline void flush() {
			fwrite(buf,1,p1+1,stdout);
			p1=-1;
		}
		inline void putc(const char &c) {
			if(p1==p2) flush();
			buf[++p1]=c;
		}
		inline void write(char *s) {
			while(*s!='\0') putc(*s),s++;
		}
		inline void write(const char *s) {
			while(*s!='\0') putc(*s),s++;
		}
		tp inline void write(Type x) {
			static char buf[30];int p=-1;
			if(x<0) {putc('-');x=-x;}
			if(x==0) putc('0');
			else for(;x;x/=10) buf[++p]=x%10+48;
			for(;p!=-1;p--) putc(buf[p]);
		}
		inline void write(const char &c) {putc(c);}
		template <typename Type,typename... Args>
		inline void write(Type t,Args ...args) {
			write(t);write(args...);
		}
	}
	using out::write;
	using out::flush;
	tp inline Type max(const Type &a,const Type &b) {
		if(a<b) return b;
		return a;
	}
	tp inline Type min(const Type &a,const Type &b) {
		if(a<b) return a;
		return b;
	}
	tp inline void swap(Type &a,Type &b) {
		a^=b^=a^=b;
	}
	tp inline Type abs(const Type &a) {
		return a>=0?a:-a;
	}
#undef tp
}
using namespace quick;

typedef long long ll;
const ll Inf=0x3f3f3f3f3f3f3f3f;
const int maxn=1000+10,maxm=10000+10,inf=0x3f3f3f3f;
int n,m;ll L;

namespace Graph {
	struct Edge {
		int v,next;
		ll w;
		std::vector<int> InTree;
		Edge(const int &v,const int &next,const ll &w)
			:v(v),next(next),w(w) {}
		Edge() {}
	}e[maxm<<1];
	int head[maxn],cnt;
	inline void clear() {
		for(int i(2);i<=cnt;i++) e[i].InTree.clear();
		memset(head,0,sizeof(int)*(n+5));
		cnt=1;
	}
	inline void AddEdge(const int &u,const int &v,const ll &w) {
		e[++cnt]=Edge(v,head[u],w);
		head[u]=cnt;
		e[++cnt]=Edge(u,head[v],w);
		head[v]=cnt;
	}
	ll d[maxn][maxn];
	inline void Dijkstra(const int &s,ll *d,const int &cut_edge=0) {
		typedef std::pair<ll,int> pii;
		static char vis[maxn];
		static std::priority_queue< pii, std::vector<pii>, std::greater<pii> > q;
		memset(vis,0x0,sizeof(char)*(n+5));
		memset(d,0x3f,sizeof(ll)*(n+5));
		d[s]=0;q.push(std::make_pair(d[s],s));
		while(!q.empty()) {
			int u=q.top().second;
			q.pop();
			if(!~vis[u]) continue;
			vis[u]=0xff;
			for(int i(head[u]);i;i=e[i].next) {
				const int &v=e[i].v;
				if(i==cut_edge||i==(cut_edge^1)) continue;
				if(d[u]+e[i].w<d[v]) {
					d[v]=d[u]+e[i].w;
					q.push(std::make_pair(d[v],v));
				}
			}
		}
		for(int i(1);i<=n;i++) if(d[i]==Inf) d[i]=L;
	}
	void Build(const int &u,const int &fa,const int &s,ll *d) {
		for(int i(head[u]);i;i=e[i].next) {
			const int &v=e[i].v;
			if(v==fa) continue;
			if(d[u]+e[i].w==d[v]) {
				e[i].InTree.push_back(s);
				e[i^1].InTree.push_back(s);
				Build(v,u,s,d);
			}
		}
	}
	std::pair<ll,ll> solve() {
		ll c=0,now=0;
		for(int i(1);i<=n;i++) {
			Dijkstra(i,d[i]);
			Build(i,0,i,d[i]);
			for(int j(1);j<=n;j++)
				c+=d[i][j];
		}
		for(int i(2);i<=cnt;i+=2) {
			static char changed[maxn];
			static ll tmp_d[maxn];
			memset(changed,0x0,sizeof(char)*(n+5));
			ll tmp=0;
			for(const auto &j: e[i].InTree) {
				changed[j]=0xff;
				Dijkstra(j,tmp_d,i);
				for(int k(1);k<=n;k++)
					tmp+=tmp_d[k];
			}
			for(int j(1);j<=n;j++) {
				if(!~changed[j]) continue;
				for(int k(1);k<=n;k++)
					tmp+=d[j][k];
			}
			now=max(now,tmp);
		}
		return std::make_pair(c,now);
	}
}

int main(void) {
#ifndef ONLINE_JUDGE
	freopen("wf.in","r",stdin);
#endif
	while(read(n,m,L)) {
		Graph::clear();
		for(int i(1);i<=m;i++) {
			int u,v;ll w;
			read(u,v,w);
			Graph::AddEdge(u,v,w);
		}
		std::pair<ll,ll> ans=Graph::solve();
		write(ans.first,' ',ans.second,'\n');
	}
	flush();
	return 0;
}

2020/8/31 16:05
加载中...