QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#230102#7640. Colorful Cyclesucup-team052#WA 62ms36344kbC++142.1kb2023-10-28 17:38:522023-10-28 17:38:52

Judging History

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

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

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;
int mx;
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]){
				int sz=0;
				do{
					++sz;
				}while(st[top--]!=v);
				mx=max(mx,sz);
			}
		}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;
		mx=0;
		rep(i,1,n)if(!dfn[i]){
			tarjan(i);
		}
		if(mx>1)puts("Yes");else puts("No");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 36344kb

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
No

result:

ok 2 token(s): yes count is 1, no count is 1

Test #2:

score: -100
Wrong Answer
time: 62ms
memory: 36044kb

input:

100000
7 10
7 2 2
6 4 2
6 1 2
7 1 3
3 4 1
6 7 1
2 6 3
3 1 2
5 3 1
2 1 1
7 10
5 7 3
7 1 1
4 6 3
6 3 1
3 4 3
4 2 2
3 2 3
1 3 3
3 7 1
1 4 2
7 10
5 6 3
3 5 2
7 2 3
7 3 3
1 2 2
4 3 2
7 4 2
6 1 2
2 6 1
7 5 2
7 10
7 1 3
7 5 3
6 4 1
7 6 1
1 4 1
3 4 2
2 7 2
1 3 1
3 5 3
5 1 3
7 10
6 7 2
3 4 3
1 4 2
5 3 2
7 4 ...

output:

Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No...

result:

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