QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#560911#1869. Power Station of ArtWorld_CreaterAC ✓570ms27168kbC++171.5kb2024-09-12 18:49:092024-09-12 18:49:09

Judging History

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

  • [2024-09-12 18:49:09]
  • 评测
  • 测评结果:AC
  • 用时:570ms
  • 内存:27168kb
  • [2024-09-12 18:49:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,nxt[2000005],head[1000005],go[2000005],k;
int s1[1000005],s2[1000005];
int a[1000005],b[1000005];
string s;
int col[1000005];
vector<pair<int,int> > v1,v2;
void add(int u,int v)
{
	nxt[++k]=head[u];
	head[u]=k;
	go[k]=v;
}
void dfs(int x,int co,int &bip,int &xo1,int &xo2)
{
	xo1^=s1[x];
	xo2^=s2[x];
	col[x]=co;
	v1.emplace_back(a[x],co^s1[x]);
	v2.emplace_back(b[x],co^s2[x]);
	for(int i=head[x];i;i=nxt[i])
	{
		int g=go[i];
		if(col[g]==-1) dfs(g,co^1,bip,xo1,xo2);
		else if(col[g]==co) bip=0;
	}
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n>>m;
		for(int i=1;i<=m;i++)
		{
			int u,v;
			cin>>u>>v;
			add(u,v);
			add(v,u);
		}
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		cin>>s;
		for(int i=1;i<=n;i++)
		{
			s1[i]=s[i-1]=='R';
		}
		for(int i=1;i<=n;i++)
		{
			cin>>b[i];
		}
		cin>>s;
		for(int i=1;i<=n;i++)
		{
			s2[i]=s[i-1]=='R';
		}
		bool fl=1;
		for(int i=1;i<=n;i++) col[i]=-1;
		for(int i=1;i<=n;i++)
		{
			v1.clear();
			v2.clear();
			if(col[i]!=-1) continue ;
			int bip=1,xo1=0,xo2=0;
			dfs(i,0,bip,xo1,xo2);
			if(xo1!=xo2) fl=0;
			sort(v1.begin(),v1.end());
			sort(v2.begin(),v2.end());
			if(bip)
			{
				for(int i=0;i<v1.size();i++)
				{
					fl&=v1[i]==v2[i];
				}
			}
			else
			{
				for(int i=0;i<v1.size();i++)
				{
					fl&=v1[i].first==v2[i].first;
				}
			}
		}
		if(fl) cout<<"YES\n";
		else cout<<"NO\n";
		for(int i=1;i<=n;i++)
		{
			head[i]=0;
		}
		k=0;
	}
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 13788kb

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: 570ms
memory: 27168kb

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