QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#52830#1869. Power Station of ArtQingyuAC ✓528ms53684kbC++1.8kb2022-10-04 15:27:422022-10-04 15:27:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-04 15:27:44]
  • 评测
  • 测评结果:AC
  • 用时:528ms
  • 内存:53684kb
  • [2022-10-04 15:27:42]
  • 提交

answer

#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define inf 1e9
#define mod 998244353
#define int ll
#define N 1000005
using namespace std;
poly S[3],S1[3];
int n,m;
poly G[N];
int tt;
int a[N],cola[N],b[N],colb[N],col[N],Ans;
void dfs(int k,int fa)
{
	S[cola[k]^col[k]].push_back(a[k]);
	S1[colb[k]^col[k]].push_back(b[k]);
	tt^=cola[k]^colb[k];
	S[2].push_back(a[k]);
	S1[2].push_back(b[k]);
	for (auto u:G[k])
	{
		if (u==fa) continue;
		if (~col[u]&&(col[u]==col[k])) Ans=1;
		if (!(~col[u]))
		{
			col[u]=col[k]^1;
			dfs(u,k);
		}
	}
}
void BellaKira()
{
	int ans=1;
	cin>>n>>m;
	for (int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	for (int i=1;i<=n;i++) cin>>a[i];
	for (int i=1;i<=n;i++)
	{
		char ch;
		cin>>ch;
		if (ch=='R') cola[i]=0;
		else cola[i]=1;
	}
	for (int i=1;i<=n;i++) cin>>b[i];
	for (int i=1;i<=n;i++)
	{
		char ch;
		cin>>ch;
		if (ch=='R') colb[i]=0;
		else colb[i]=1;
	}
	for (int i=1;i<=n;i++) col[i]=-1;
	for (int i=1;i<=n;i++)
		if (col[i]==-1)
		{
			Ans=0;
			tt=0;
			col[i]=0;
			dfs(i,0);
			ans&=tt^1;
			for (int j=0;j<3;j++) sort(S[j].begin(),S[j].end()),sort(S1[j].begin(),S1[j].end());
			if (Ans)
			{
				if (S[2]==S1[2]) ans&=1;
				else ans&=0;
			}
			else
			{
				if (S[0]==S1[0]&&S[1]==S1[1]&&S[2]==S1[2])
					ans&=1;
				else ans&=0;
			}
			for (int j=0;j<3;j++) poly().swap(S[j]),poly().swap(S1[j]);
		}
	if (ans) cout<<"YES\n";
	else cout<<"NO\n";	
	for (int i=1;i<=n;i++) poly().swap(G[i]);
}
signed main()
{
	IOS;
	cin.tie(0);
	int T=1;
	cin>>T;
	while (T--)
	{
		BellaKira();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 528ms
memory: 53684kb

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:

ok 25054 lines