QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#543661#1869. Power Station of ArtPhantomThreshold#WA 246ms43880kbC++201.9kb2024-09-01 17:50:422024-09-01 17:50:42

Judging History

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

  • [2024-09-01 17:50:42]
  • 评测
  • 测评结果:WA
  • 用时:246ms
  • 内存:43880kb
  • [2024-09-01 17:50:42]
  • 提交

answer

#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define ll long long
#define int long long
using namespace std;
using ull=unsigned long long;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	mt19937_64 rng(41287482);
	
	const int maxw=1e6;
	vector<ull> w(maxw+5);
	for(int i=0;i<=maxw;i++)
		w[i]=rng();
	
	int Tcase; cin>>Tcase;
	while(Tcase--)
	{
		int n,m;
		cin>>n>>m;
		vector<vector<int>> G(n+5);
		for(int i=1;i<=m;i++)
		{
			int u,v;
			cin>>u>>v;
			G[u].push_back(v);
			G[v].push_back(u);
		}
		vector<int> a(n+5),b(n+5);
		string ca,cb;
		for(int i=1;i<=n;i++)cin>>a[i];
		cin>>ca;
		ca=' '+ca;
		for(int i=1;i<=n;i++)cin>>b[i];
		cin>>cb;
		cb=' '+cb;
		vector<int> bel(n+5),good(n+5),col(n+5);
		vector<int> cntr(n+5);
		vector<vector<ull>> sum(2,vector<ull>(n+5));
		function<void(int,int)> dfs=[&](int r,int u)
		{
			bel[u]=r;
			for(auto v:G[u])
			{
				if(not bel[v])
				{
					col[v]=col[u]^1;
					dfs(r,v);
				}
				else if(col[u]==col[v])
					good[u]=0;
			}
		};
		for(int i=1;i<=n;i++)
		{
			if(not bel[i])
			{
				good[i]=1;
				dfs(i,i);
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(good[bel[i]])
			{
				if(col[i]==1)
				{
					if(ca[i]=='R')cntr[bel[i]]++;
					if(cb[i]=='R')cntr[bel[i]]--;
				}
				else
				{
					if(ca[i]=='B')cntr[bel[i]]++;
					if(cb[i]=='B')cntr[bel[i]]--;
				}
				sum[(ca[i]=='R')^col[i]][bel[i]]+=w[a[i]];
				sum[(cb[i]=='R')^col[i]][bel[i]]-=w[b[i]];
			}
			else
			{
				if(ca[i]=='R')cntr[bel[i]]^=1;
				if(cb[i]=='R')cntr[bel[i]]^=1;
				sum[0][bel[i]]+=w[a[i]];
				sum[0][bel[i]]-=w[b[i]];
			}
		}
		int ok=1;
		for(int i=1;i<=n;i++)
		{
			if(cntr[i]!=0)ok=0;
			if(sum[0][i]!=0 or sum[1][i]!=0)ok=0;
		}
		if(ok)cout<<"YES\n";
		else cout<<"NO\n";
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 1
1 2
3 4
RR
4 3
BB
3 2
1 2
2 3
1 1 1
RBR
1 1 1
BBB
3 3
1 2
2 3
3 1
1 1 1
RBR
1 1 1
BBB

output:

YES
NO
YES

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 246ms
memory: 43880kb

input:

25054
5 10
4 5
4 2
4 3
4 1
5 2
5 3
5 1
2 3
2 1
3 1
12 2 9 10 7
RRRBB
10 2 9 7 12
RRBRB
1 0
4
R
4
R
8 4
4 3
1 5
8 5
6 5
7 2 11 10 9 6 3 5
RBRBBRBR
7 2 10 11 6 5 3 9
RBRBBRBR
7 4
7 2
5 1
5 6
5 4
12 5 9 14 5 12 12
RRBRBRR
14 12 9 5 12 12 5
RBBRBRB
10 1
4 6
5 3 2 9 7 3 11 11 6 8
RRRBRRBBBR
5 3 2 3 7 9 1...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
NO
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
YES
NO
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
YES
NO
NO...

result:

wrong answer 113th lines differ - expected: 'YES', found: 'NO'