QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#230249#7640. Colorful Cyclesucup-team052#WA 96ms44552kbC++142.9kb2023-10-28 17:57:422023-10-28 17:57:42

Judging History

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

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

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,n)e[i].clear();
		vvs.clear();
		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)dfn[i]=low[i]=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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 96ms
memory: 40484kb

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
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
No
No
Yes
Yes
No
No
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
No
Yes
Yes
No
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Y...

result:

wrong answer expected YES, found NO [4th token]