QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#229091#7640. Colorful Cyclesucup-team266#WA 308ms44992kbC++142.9kb2023-10-28 15:01:342023-10-28 15:01:35

Judging History

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

  • [2024-07-04 22:58:32]
  • hack成功,自动添加数据
  • (/hack/728)
  • [2023-10-28 15:01:35]
  • 评测
  • 测评结果:WA
  • 用时:308ms
  • 内存:44992kb
  • [2023-10-28 15:01:34]
  • 提交

answer

/*
Things to notice:
1. do not calculate useless values
2. do not use similar names
 
Things to check:
1. submit the correct file
2. time (it is log^2 or log)
3. memory
4. prove your naive thoughts 
5. long long
6. corner case like n=0,1,inf or n=m
7. check if there is a mistake in the ds or other tools you use
8. fileio in some oi-contest

9. module on time 
10. the number of a same divisor in a math problem
11. multi-information and queries for dp and ds problems
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
const ll D=1e6;
const int mod=998244353;
const int inf=0x3f3f3f3f;
int n,m;
vector <array<int,3> > h;
vector <pii > g[1000005];
struct LCA
{
	int dep[1000005],dfn[1000005],times;
	ll dist[1000005];
	int st[21][2000005],Lg[2000005];
	void dfs(int u,int fa)
	{
		dfn[u]=++times,st[0][times]=u;
		for(int i=0;i<g[u].size();i++)
		{
			int v=g[u][i].fi;
			if(v==fa) continue;
			ll w=1LL;
			if(g[u][i].se==2) w=1LL*D;
			if(g[u][i].se==3) w=1LL*D*D;
			dep[v]=dep[u]+1,dist[v]=dist[u]+w,dfs(v,u);
			st[0][++times]=u;
		}
	}
	int mindep(int x,int y)
	{
		if(dep[x]<dep[y]) return x;
		return y;
	}
	void build()
	{
		times=0,dep[1]=0,dist[1]=0;
		dfs(1,-1);
		Lg[1]=0,Lg[2]=1;
		for(int i=3;i<=times;i++) Lg[i]=Lg[i/2]+1;
		for(int k=1;k<21;k++) for(int i=1;i+(1<<k)-1<=times;i++) 
			st[k][i]=mindep(st[k-1][i],st[k-1][i+(1<<(k-1))]);
	}
	int getlca(int u,int v)
	{
		u=dfn[u],v=dfn[v];
		if(u>v) swap(u,v);
		int s=Lg[v-u+1];
		return mindep(st[s][u],st[s][v-(1<<s)+1]);
	}
	ll getdis(int u,int v)
	{
		int l=getlca(u,v);
		return dist[u]+dist[v]-2LL*dist[l];	
	}
}Lca;
mt19937 rnd(114514);
const int B=30;
int fa[1000005];
int find(int x)
{
	if(fa[x]==x) return x;
	return fa[x]=find(fa[x]);
}
void merge(int x,int y)
{
	int xx=find(x),yy=find(y);
	if(xx!=yy) fa[xx]=yy;
}
bool chk()
{
	for(int i=1;i<=n;i++) g[i].clear(),fa[i]=i;
	for(int i=h.size()-1;i>=0;i--) swap(h[i],h[rnd()%(i+1)]);
	vector <int> idx;
	for(int i=0;i<h.size();i++)
	{
		int u=h[i][0],v=h[i][1];
		if(find(u)==find(v)) 
		{
			idx.pb(i);
			continue;
		}
		merge(u,v),g[u].pb(mp(v,h[i][2])),g[v].pb(mp(u,h[i][2]));
	}
	Lca.build();
	for(int _=0;_<idx.size();_++)
	{
		array<int,3> e=h[idx[_]];
		ll t=Lca.getdis(e[0],e[1]);
		if(e[2]==1) t++;
		if(e[2]==2) t+=1LL*D;
		if(e[2]==3) t+=1LL*D*D;
		int ok=1;
		for(int j=0;j<3;j++)
		{
			if(t%D==0) ok=0;
			t/=D;
		}
		if(ok) return 1;
	}
	return 0;
}
void solve()
{
	cin>>n>>m;
	h.clear();
	while(m--)
	{
		int u,v,w;
		cin>>u>>v>>w;
		h.pb({u,v,w});
	}
	for(int i=1;i<=B;i++) if(chk())
	{
		cout<<"Yes\n";
		return;
	}
	cout<<"No\n";
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _=1;
	cin>>_;
	while(_--) solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 6ms
memory: 44992kb

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: 308ms
memory: 43796kb

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

result:

wrong answer expected YES, found NO [6303rd token]