QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#230214#7640. Colorful Cyclesucup-team052#WA 4ms36296kbC++142.8kb2023-10-28 17:53:082023-10-28 17:53:08

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 22:58:32]
  • hack成功,自动添加数据
  • (/hack/728)
  • [2023-10-28 17:53:08]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:36296kb
  • [2023-10-28 17:53:08]
  • 提交

answer

#include<bits/stdc++.h>
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#define DD(...) D(#__VA_ARGS__ "="),debug_helper::debug(__VA_ARGS__),D("\n")
#include"/home/xay5421/debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define each(x,v) for(auto&x:v)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
template<class T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;}
template<class T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);}
using namespace std;
using LL=long long;
using ULL=unsigned long long;
const int N=1000005;
int T,n,m,eu[N],ev[N],ew[N];
int last[N],fa[N];
int find(int u){return u==fa[u]?u:fa[u]=find(fa[u]);}
vector<pair<int,int> >e[N];
int dfn[N],low[N],idx,st[N],top;
vector<pair<vector<int>,int> >vvs;
bool vis[N];
void tarjan(int u){
	dfn[u]=low[u]=++idx;
	st[++top]=u;
	for(auto&[v,w]:e[u]){
		if(!dfn[v]){
			tarjan(v);
			low[u]=min(low[u],low[v]);
			if(low[v]>=dfn[u]){
				vector<int>vs;
				do{
					vs.pb(st[top]);
				}while(st[top--]!=v);
				vvs.eb(vs,u);
			}
		}else{
			low[u]=min(low[u],dfn[v]);
		}
	}
}
int main(){
#ifdef xay5421
	freopen("a.in","r",stdin);
#endif
	rd(T);
	while(T--){
		rd(n),rd(m);
		rep(i,1,n)last[i]=-1,fa[i]=i;
		rep(i,1,m){
			int u,v,w;
			rd(u),rd(v),rd(w);
			e[u].eb(v,w);
			e[v].eb(u,w);
			eu[i]=u,ev[i]=v,ew[i]=w;
			if(last[u]==-1){
				last[u]=w;
			}else if(last[u]!=w){
				last[u]=0;
			}
			if(last[v]==-1){
				last[v]=w;
			}else if(last[v]!=w){
				last[v]=0;
			}
		}
		rep(u,1,n){
			if(last[u]>0){
				for(auto&[v,w]:e[u]){
					fa[find(u)]=find(v);
				}
			}
		}
		rep(i,1,n)e[i].clear();
		rep(i,1,m){
			eu[i]=find(eu[i]);
			ev[i]=find(ev[i]);
			e[eu[i]].eb(ev[i],ew[i]);
			e[ev[i]].eb(eu[i],ew[i]);
		}
		top=0;
		rep(i,1,n)if(!dfn[i]){
			tarjan(i);
		}
		bool ok=0;
		for(auto &[vs,u]:vvs){
			vis[u]=1;
			last[u]=-1;
			fa[u]=u;
			for(auto &v:vs){
				vis[v]=1;
				last[v]=-1;
				fa[v]=v;
			}
			auto push=[&](int x,int y){
				if(last[x]==-1)last[x]=y;
				if(last[x]!=y)last[x]=0;
			};
			for(auto &v:vs){
				for(auto &[v_,w]:e[v]){
					if(vis[v_]){
						push(v,w);
						push(v_,w);
					}
				}
			}
			for(auto &v:vs){
				for(auto &[v_,w]:e[v]){
					if(last[v]>0){
						fa[find(v)]=find(v_);
					}
					if(last[u]>0&&v_==u){
						fa[find(v)]=find(v_);
					}
				}
			}
			
			int tot=find(u)==u;
			for(auto &v:vs){
				tot+=find(v)==v;
			}
			if(tot>2){
				ok=1;
			}
			
			vis[u]=0;
			for(auto &v:vs){
				vis[v]=0;
			}
		}
		if(ok)puts("Yes");else puts("No");
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 36296kb

input:

2
3 3
1 2 3
2 3 1
1 3 2
5 6
1 2 1
2 3 1
1 3 2
3 4 3
3 5 3
4 5 3

output:

Yes
Yes

result:

wrong answer expected NO, found YES [2nd token]