QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#620632#1869. Power Station of ArtdengziyueRE 0ms0kbC++141.9kb2024-10-07 19:56:172024-10-07 19:56:45

Judging History

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

  • [2024-10-07 19:56:45]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-07 19:56:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define max_n 1000000
int tid;
int n;
int m;
vector<int>g[max_n+2];
int a[max_n+2];
int b[max_n+2];
int at[max_n+2];
int bt[max_n+2];
char bs[max_n+2];
int col[max_n+2];
bool ef=true;//二分图
vector<int>ga[2];//总的连通块里的数 
vector<int>gaa[2][2]; 
int sb=0;
bool ans=true;
inline bool check(vector<int>&a,vector<int>&b){
	if(a.size()!=b.size())return false;
	sort(a.begin(),a.end()); sort(b.begin(),b.end());
	for(int i=0,len=a.size();i<len;++i){
		if(a[i]!=b[i])return false;
	}
	return true;
}
void dfs(int u){
	ga[0].push_back(a[u]); ga[1].push_back(at[u]);
	gaa[0][b[u]^col[u]].push_back(a[u]); gaa[1][bt[u]^col[u]].push_back(at[u]);
	sb^=b[u]^bt[u];
	for(auto v:g[u]){
		if(col[v]==-1){col[v]=col[u]^1; dfs(v);}
		else if(col[u]==col[v])ef=false;
	}
}
int main(){
	freopen("graph.in","r",stdin);
	freopen("graph.out","w",stdout);
	scanf("%d",&tid);
	for(int ca=1;ca<=tid;++ca){
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;++i)g[i].clear();
		for(int i=1,u,v;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",bs+1);
		for(int i=1;i<=n;++i)b[i]=(bs[i]=='B');
		for(int i=1;i<=n;++i)scanf("%d",at+i);
		scanf("%s",bs+1);
		for(int i=1;i<=n;++i)bt[i]=(bs[i]=='B');
		ans=true;
		for(int i=1;i<=n;++i)col[i]=-1;
		for(int i=1;i<=n;++i){
			if(col[i]!=-1)continue;
			ef=true;
			ga[0].clear(); gaa[0][0].clear(); gaa[0][1].clear();
			ga[1].clear(); gaa[1][0].clear(); gaa[1][1].clear();
			col[i]=0; sb=0; dfs(i);
			if(!check(ga[0],ga[1])){ans=false; break;}
			if(ef){
				if(!check(gaa[0][0],gaa[1][0])||!check(gaa[0][1],gaa[1][1])){
					ans=false; break;
				}
			}
			else{
				if(sb){ans=false; break;}
			}
		}
		if(ans)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

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: