QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#232610#7640. Colorful Cyclesucup-team1004TL 12ms125824kbC++142.2kb2023-10-30 17:31:422023-10-30 17:31:42

Judging History

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

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

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#ifdef DEBUG
template<typename T>
ostream& operator << (ostream &out,const vector<T> &x){
	if(x.empty())return out<<"[]";
	out<<'['<<x[0];
	for(int i=1,len=x.size();i<len;i++)out<<','<<x[i];
	return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
	cerr<<x<<endl;
}
template<typename T,typename ... S>
void debug(T x,S...y){
	cerr<<x<<' ',debug(y...);
}
#endif
const int N=1e6+10,V=N*2;
int T,n,m,k;
vector<pair<int,int> >A[N];
vector<int>B[V];
vector<tuple<int,int,int> >E[V];
int dft,top,dfn[N],low[N],stk[N];
int fa[V];
void add(int u,int v){
	// debug(u,v);
	B[u].push_back(v),B[v].push_back(u);
}
#define v e.first
#define w e.second
void tarjan(int u,int fa=0){
	dfn[u]=low[u]=++dft,stk[++top]=u;
	for(auto e:A[u])if(v^fa){
		if(!dfn[v]){
			tarjan(v),low[u]=min(low[u],low[v]);
			if(low[v]>=dfn[u]){
				add(++k,u);
				do add(k,stk[top]);while(stk[top--]^v);
			}
		}else low[u]=min(low[u],dfn[v]);
	}
}
void build(){
	for(int u=1;u<=n;u++){
		for(auto e:A[u]){
			if(u>v)continue;
			if(fa[u]==fa[v]||fa[fa[u]]==v)E[fa[u]].push_back({u,v,w});
			else E[fa[v]].push_back({u,v,w});
		}
	}
}
#undef v
#undef w
void dfs(int u){
	for(int v:B[u])if(v^fa[u]){
		fa[v]=u,dfs(v);
	}
}
int col[N];
bool get(){
	scanf("%d%d",&n,&m),k=n;
	for(int u,v,w;m--;){
		scanf("%d%d%d",&u,&v,&w);
		A[u].push_back({v,w}),A[v].push_back({u,w});
	}
	for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i);
	for(int i=1;i<=k;i++)if(!fa[i])dfs(i);
	build();
	for(int i=n+1;i<=k;i++){
		int sum=0;
		for(int v:B[i])col[v]=0;
		for(auto e:E[i]){
			int u,v,w;
			tie(u,v,w)=e;
			col[u]|=1<<w,col[v]|=1<<w,sum|=1<<w;
		}
		if(__builtin_popcount(sum)!=3)continue;
		int cnt=0;
		for(int v:B[i]){
			cnt+=__builtin_popcount(col[v])>1;
		}
		if(cnt>2)return 1;
	}
	return 0;
}
void clr(){
	dft=top=0;
	for(int i=1;i<=n;i++){
		A[i].clear();
		dfn[i]=low[i]=0;
	}
	for(int i=1;i<=k;i++){
		B[i].clear(),E[i].clear();
		fa[i]=0;
	}
}
int main(){
	for(scanf("%d",&T);T--;)puts(get()?"Yes":"No");
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 12ms
memory: 125824kb

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
Time Limit Exceeded

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: