QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#296075#6679. Not Another Path Query Problem1366397866WA 11ms58368kbC++141.2kb2024-01-02 07:49:532024-01-02 07:49:53

Judging History

This is the latest submission verdict.

  • [2024-01-02 07:49:53]
  • Judged
  • Verdict: WA
  • Time: 11ms
  • Memory: 58368kb
  • [2024-01-02 07:49:53]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define PII pair<int,int>
const int N=1e5+10;
int n,m,q,v;
int f[N][70]; 
void init()
{
	for(int i=0;i<70;i++)
	{
		for(int j=0;j<N;j++)
		{
			f[j][i]=j;
		}
	}
}
int getf(int i,int x)
{
	if(x==f[x][i])return x;
	f[x][i]=getf(i,f[x][i]);
	return f[x][i];
}
void solve()
{
	cin>>n>>m>>q>>v;
	init();
	while(m--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		f[getf(60,a)][60]=getf(60,b);
		for(int i=59;i>=0;i--)
		{
			int ans=(c>>i&1);
			if(ans==1)
			{
				f[getf(i,a)][i]=getf(i,b);
			}
			else 
			{
				if((v>>i&1)==1)break;
			}
		}
	}
	while(q--)
	{
		int a,b;
		cin>>a>>b;
		int res=0;
		for(int i=59;i>=0;i--)
		{
			if(getf(i,a)==getf(i,b))
			{
				res=res*2+1;
			}
			else res*=2;
		}
		if(v==0)
		{
			if(res==0)
			{
				if(getf(60,a)==getf(60,b))cout<<"Yes"<<endl;
				else cout<<"No"<<endl;
			}
		}
		else if(res>=v)cout<<"Yes"<<endl;
		else cout<<"No"<<endl; 
	}
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T=1;
//	cin>>T;
	while(T--)solve();
	return 0;
}  

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 58368kb

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

result:

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

Test #2:

score: 0
Accepted
time: 4ms
memory: 58316kb

input:

3 4 1 4
1 2 3
1 2 5
2 3 2
2 3 6
1 3

output:

Yes

result:

ok YES

Test #3:

score: -100
Wrong Answer
time: 11ms
memory: 58308kb

input:

100 2000 50000 0
32 52 69658009083393280
26 38 868250171554967916
87 32 743903879320440454
22 15 19782587273744714
57 98 845866434191429143
42 95 1145336983294966993
67 40 1036117659380117375
46 24 265457274847122243
63 44 438254608190938148
28 23 992625102587165494
57 87 558124114385470345
6 17 535...

output:


result:

wrong answer Answer contains longer sequence [length = 50000], but output contains 0 elements