QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#582122 | #1869. Power Station of Art | cqbztzl | WA | 259ms | 44880kb | C++14 | 2.0kb | 2024-09-22 15:24:31 | 2024-09-22 15:24:32 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,n,m,cnt,h[1000005],vis[1000005],col[1000005],a[1000005],b[1000005];
struct edge{
int v,nxt;
}e[2000005];
char s[1000005],t[1000005];
void adde(int u,int v){
e[++cnt].nxt=h[u];
h[u]=cnt;
e[cnt].v=v;
}
bool fff;
vector<int>nod;
void dfs(int x,int c){
if(col[x]!=-1){
if(col[x]!=c)fff=0;
return;
}
nod.push_back(x);
col[x]=c;
for(int i=h[x];i;i=e[i].nxt){
dfs(e[i].v,c^1);
}
}
signed main()
{
scanf("%lld",&T);
while(T--){
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;i++)h[i]=vis[i]=0,col[i]=-1;
cnt=0;
for(int i=1,u,v;i<=m;i++)scanf("%lld%lld",&u,&v),adde(u,v),adde(v,u);
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
scanf("%s",s+1);
for(int i=1;i<=n;i++)scanf("%lld",&b[i]);
scanf("%s",t+1);
bool FFF=1;
for(int i=1;i<=n;i++){
if(col[i]==-1){
fff=1;
nod.clear();
dfs(i,1);
vector<int>A,B;
for(int x:nod)A.push_back(a[x]),B.push_back(b[x]);
sort(A.begin(),A.end());
sort(B.begin(),B.end());
for(int j=0;j<A.size();j++){
if(A[j]!=B[j]){
FFF=0;
break;
}
}
if(!FFF)break;
if(fff){
int A=0,B=0;
vector<int>C,D;
for(int x:nod){
if(col[x]==0){
A+=(s[x]=='B');
B+=(t[x]=='B');
if(s[x]=='B')C.push_back(a[x]);
if(t[x]=='B')D.push_back(b[x]);
}
else{
A+=(s[x]=='R');
B+=(t[x]=='R');
if(s[x]=='R')C.push_back(a[x]);
if(t[x]=='R')D.push_back(b[x]);
}
}
if(A!=B){
FFF=0;
break;
}
sort(C.begin(),C.end());
sort(D.begin(),D.end());
for(int i=0;i<C.size();i++){
if(C[i]!=D[i]){
FFF=0;
break;
}
}
}
}
}
if(FFF)puts("YES");
else puts("NO");
}
return 0;
}
/*
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
*/
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 15916kb
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: -100
Wrong Answer
time: 259ms
memory: 44880kb
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 YES 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 YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES NO YES NO ...
result:
wrong answer 10th lines differ - expected: 'NO', found: 'YES'