QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#32272#3996. RaceDaBenZhongXiaSongKuaiDi#WA 5ms11196kbC++141.7kb2022-05-18 16:26:442022-05-18 16:26:45

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-18 16:26:45]
  • Judged
  • Verdict: WA
  • Time: 5ms
  • Memory: 11196kb
  • [2022-05-18 16:26:44]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
vector <pair<int,int> > e[200005];
int fa[200005],s[200005][35],Or[200005],w[200005];
int U[200005],V[200005],W[200005];
inline int ff(int x)
{
	if(fa[x]==x) return x;
	return fa[x]=ff(fa[x]);
}
inline void ins(int x,int y)
{
	for(int i=30;i>=0;i--)
	{
		if(y&(1<<i))
		{
			if(s[x][i]) y^=s[x][i];
			else
			{
				s[x][i]=y;
				return ;
			}
		}
	}
}
inline int ask(int x,int y)
{
	for(int i=30;i>=0;i--)
	{
		if(y&(1<<i))
		{
			if(s[x][i]) y^=s[x][i];
			else return 0;
		}
	}
	return 1;
}
inline void mer(int x,int y)
{
	x=ff(x),y=ff(y);
	if(x==y) return ;
	Or[x]=Or[y]=(Or[x]|Or[y]);
	for(int i=0;i<=30;i++)
		if(s[y][i]) ins(x,s[y][i]);
	fa[y]=x; 
}
inline void dfs(int u,int f)
{
	for(auto v:e[u])
		if(v.first!=f) w[v.first]=w[u]^v.second,dfs(v.first,u);
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m,k,q;
	cin >> n >> m >> k >> q;
	int S=(1<<k)-1;
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		cin >> U[i] >> V[i] >> W[i];
		W[i]=(1<<W[i]-1);
		if(ff(U[i])!=ff(V[i]))
		{
			e[U[i]].push_back({V[i],W[i]});
			e[V[i]].push_back({U[i],W[i]});
		}
		mer(U[i],V[i]),Or[ff(U[i])]|=W[i];
	}
	for(int i=1;i<=n;i++)
		if(fa[i]==i) dfs(i,0);
	for(int i=1;i<=m;i++)
	{
		int X=w[U[i]]^w[V[i]]^W[i];
		if(X) ins(ff(U[i]),X);
	}
	for(int i=1;i<=n;i++) if(fa[i]==i) ins(i,S);
	while(q--)
	{
		int u,v;
		cin >> u >> v;
		if(ff(u)!=ff(v))
		{
			cout << "No\n";
			continue;
		}
		if(Or[ff(u)]!=S)
		{
			cout << "No\n";
			continue;
		}
		if(!ask(ff(u),w[u]^w[v]))
		{
			cout << "No\n";
			continue;
		}
		cout << "Yes\n";
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 11180kb

input:

7 9 3 4
1 2 1
2 3 1
3 1 2
1 4 3
5 6 2
6 7 1
6 7 3
7 7 2
5 5 1
6 7
1 4
2 4
2 5

output:

Yes
No
Yes
No

result:

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

Test #2:

score: 0
Accepted
time: 5ms
memory: 11196kb

input:

9 10 3 5
7 2 2
4 2 1
7 1 1
2 8 1
1 7 2
2 7 3
2 8 1
7 2 1
7 5 1
8 1 2
6 4
6 7
8 4
5 1
8 6

output:

No
No
Yes
Yes
No

result:

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

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 10380kb

input:

39 30 5 999
12 22 4
11 1 1
28 13 3
35 1 4
7 17 2
20 19 4
28 7 5
15 33 5
31 38 5
13 33 4
13 35 2
16 12 5
13 33 1
21 15 3
23 32 1
19 16 3
3 22 3
11 14 2
31 26 5
32 17 5
34 17 3
31 26 2
10 37 1
1 3 1
30 12 4
1 35 3
6 1 2
25 15 2
39 23 5
10 5 3
24 34
32 27
4 13
37 28
31 36
12 11
24 6
22 32
7 17
1 15
22 ...

output:

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

result:

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