QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#613927#1869. Power Station of Artxzf_200906RE 0ms0kbC++141.7kb2024-10-05 15:04:502024-10-05 15:10:00

Judging History

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

  • [2024-10-05 15:10:00]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-05 15:04:50]
  • 提交

answer

#include <bits/stdc++.h>
#define LL long long
using namespace std;
vector<int> e[1000000];
int a[1000000],b[1000000],c[1000000],d[1000000],col[1000000];
vector<int> poi;
bool dfs(int p){
	poi.push_back(p);
	bool ret=1;
	for(auto it:e[p]){
		if(col[it]!=-1){
			if(col[it]==col[p]) ret=0;
		}
		else{
			col[it]=col[p]^1;
			ret&=dfs(it);
		}
	}
	return ret;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	freopen("tutonggou.in","r",stdin);
	freopen("tutonggou.out","w",stdout);
	int T;
	cin>>T;
	while(T--){
		int n,m;
		cin>>n>>m;
		for(int i=1;i<=n;i++){
			e[i].clear();
			col[i]=-1;
		}
		for(int i=1;i<=m;i++){
			int u,v;
			cin>>u>>v;
			e[u].push_back(v);
			e[v].push_back(u);
		}
		for(int i=1;i<=n;i++) cin>>a[i];
		for(int i=1;i<=n;i++){
			char ch;
			cin>>ch;
			if(ch=='R') b[i]=1;
			else b[i]=0;
		}
		for(int i=1;i<=n;i++) cin>>c[i];
		for(int i=1;i<=n;i++){
			char ch;
			cin>>ch;
			if(ch=='R') d[i]=1;
			else d[i]=0;
		}
		bool fl=1;
		for(int i=1;i<=n;i++){
			if(col[i]==-1){
				poi.clear();
				col[i]=0;
				if(dfs(i)){
					map<int,int> m1,m2;
					for(auto it:poi){
						if(b[it]==col[it]) m1[a[it]]++;
						else m2[a[it]]++;
						if(d[it]==col[it]) m1[c[it]]--;
						else m2[c[it]]--;
					}
					for(auto it:m1){
						if(it.second!=0) fl=0;
					}
					for(auto it:m2){
						if(it.second!=0) fl=0;
					}
				}
				else{
					map<int,int> m1;
					int cnt=0;
					for(auto it:poi){
						m1[a[it]]++;
						m1[c[it]]--;
						cnt+=b[it];
						cnt-=d[it];
					}
					for(auto it:m1){
						if(it.second!=0) fl=0;
					}
					if(cnt&1) fl=0;
				}
			}
			if(fl==0) break;
		}
		cout<<(fl?"YES\n":"NO\n");
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Dangerous Syscalls

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:


result: