QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#620636 | #1869. Power Station of Art | dengziyue | AC ✓ | 272ms | 58688kb | C++14 | 1.8kb | 2024-10-07 19:57:13 | 2024-10-07 19:57:22 |
Judging History
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(){
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 36348kb
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: 272ms
memory: 58688kb
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