QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#52118#1869. Power Station of ArttricyzhkxAC ✓437ms42676kbC++141.3kb2022-10-04 10:36:402022-10-04 10:36:43

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 10:36:43]
  • 评测
  • 测评结果:AC
  • 用时:437ms
  • 内存:42676kb
  • [2022-10-04 10:36:40]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
int ca[2],cb[2],a[1000010],b[1000010],col[1000010];
bool flag;
char s[1000010],t[1000010];
vector<int> G[1000010];
vector<pair<int,int>> A,B;
void dfs(int u,int c)
{
	if(col[u])
	{
		if(col[u]!=c) flag=0;
		return;
	}
	col[u]=c;A.emplace_back(a[u],(col[u]>0)^s[u]);B.emplace_back(b[u],(col[u]>0)^t[u]);
	ca[(int)s[u]]++;cb[(int)t[u]]++;
	for(int v:G[u]) dfs(v,-c);
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n,m,u,v;
		scanf("%d%d",&n,&m);
		for(int i=1;i<=m;i++)
		{
			scanf("%d%d",&u,&v);
			G[u].push_back(v);G[v].push_back(u);
		}
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		scanf("%s",s+1);
		for(int i=1;i<=n;i++) scanf("%d",&b[i]);
		scanf("%s",t+1);
		for(int i=1;i<=n;i++) col[i]=0,s[i]=(s[i]=='R'?1:0),t[i]=(t[i]=='R'?1:0);
		bool ans=1;
		for(int i=1;i<=n;i++)
			if(!col[i])
			{
				flag=1;dfs(i,1);
				sort(A.begin(),A.end());
				sort(B.begin(),B.end());
				int sz=A.size();
				if(flag) for(int i=0;i<sz;i++) ans&=(A[i]==B[i]);
				else
				{
					for(int i=0;i<sz;i++) ans&=(A[i].first==B[i].first);
					ans&=((ca[0]&1)==(cb[0]&1));
				}
				A.clear();B.clear();
				ca[0]=ca[1]=cb[0]=cb[1]=0;
				if(!ans) break;
			}
		puts(ans?"YES":"NO");
		for(int i=1;i<=n;i++) G[i].clear();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 437ms
memory: 42676kb

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