QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#695364#6679. Not Another Path Query ProblemmonuiWA 1ms7804kbC++231.2kb2024-10-31 19:51:392024-10-31 19:51:48

Judging History

This is the latest submission verdict.

  • [2024-10-31 19:51:48]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7804kb
  • [2024-10-31 19:51:39]
  • Submitted

answer


#include<bits/stdc++.h>
using namespace std;
#define no cout<<"No"<<endl
#define yes cout<<"Yes"<<endl
#define int long long
const int N=1e5+10,M=5e5+10;
int cnt;
int p[N][63];
int f[N];
int n,m,q,v;
struct node
{
	int a,b;
	int w;
}e[M];
int find(int x,int y)
{
	return p[x][y]==x?x:p[x][y]=find(p[x][y],y);
}
int get(int x)
{
	return f[x]==x?x:f[x]=get(f[x]);
}
void solve()
{
	cin>>n>>m>>q>>v;
	for(int k=0;k<=62;k++)
		for(int i=1;i<=n;i++)
			p[i][k]=i;
	for(int i=1;i<=n;i++) f[i]=i;
	for(int i=1;i<=m;i++)
	{
		int a,b;
		int w;
		cin>>a>>b>>w;
		int l=get(a),r=get(b);
		if(l!=r) f[l]=r;
		if(w<v) continue;
		e[++cnt]={a,b,w};
	}
	for(int i=1;i<=cnt;i++)
	{
		int a=e[i].a,b=e[i].b,w=e[i].w;
		bool flag=true;
		for(int j=62,ans=0;j>=0;j--)
		{
			if(1ll<<j&v){
				ans|=(1ll<<j);
				if((w&ans)!=ans) break;
			}
			if(w&(1ll<<j))
			{
				a=find(a,j),b=find(b,j);
				if(a!=b) p[a][j]=b;
			}
		}
	}

	while(q--)
	{
		int a,b;
		cin>>a>>b;
		int id=0;
		for(int i=62;i>=0;i--)
		{
			if(find(a,i)==find(b,i)){
				yes;
			}
		}
		no;
	}
}
signed main()
{
	ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
	int t=1;
//	cin>>t;
	while(t--)
		solve();
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7804kb

input:

9 8 4 5
1 2 8
1 3 7
2 4 1
3 4 14
2 5 9
4 5 7
5 6 6
3 7 15
1 6
2 7
7 6
1 8

output:

Yes
Yes
No
No
Yes
Yes
Yes
No
No

result:

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