QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#618401 | #1869. Power Station of Art | FanyuX | WA | 145ms | 45076kb | C++14 | 1.8kb | 2024-10-06 21:48:33 | 2024-10-06 21:48:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ri register
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
const int inf=0x3f3f3f3f;
inline int rd(){
int x=0,y=1;char c=getchar();
for(;c<'0'||c>'9';c=getchar())if(c=='-')y=-1;
for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c^48);
return x*y;
}
const int N=1e6+5;
int n,m,t,w[2][N];
bool vis[N],c[N],flg;
vector<int>e[N],vt[2];
char s[2][N];
void dfs(int u,bool co){
if(vis[u]){
flg|=c[u]!=co;
return ;
}
c[u]=co;vis[u]=1;
vt[co].pb(u);
for(auto v:e[u])dfs(v,!co);
}
void sol(){
for(int i=1;i<=n;i++)if(!vis[i]){
flg=0;
for(int j=0;j<2;j++)vt[j].clear();
dfs(i,0);
if(!flg){
vector<int>val[2];
for(int x=0;x<2;x++)
for(auto j:vt[x])
for(int k=0;k<2;k++)
if(x)val[k].pb((s[k][j]^'B'^'R')*N+w[k][j]);
else val[k].pb(s[k][j]*N+w[k][j]);
for(int j=0;j<2;j++)
sort(val[j].begin(),val[j].end());
for(int j=0;j<val[0].size();j++)
if(val[0][j]!=val[1][j])
return puts("NO"),void();
}else{
int cnt[2]={};
vector<int>val[2];
for(int x=0;x<2;x++)
for(auto j:vt[x])
for(int k=0;k<2;k++)
cnt[k]+=s[k][j]=='B'?-1:1,
val[k].pb(w[k][j]);
for(int j=0;j<2;j++)
sort(val[j].begin(),val[j].end());
for(int j=0;j<val[0].size();j++)
if(val[0][j]^val[1][j])return puts("NO"),void();
if(cnt[0]+cnt[1]&1)return puts("NO"),void();
}
}
puts("YES");
}
signed main(){
for(t=rd();t--;){
n=rd();m=rd();
for(int i=1;i<=n;i++)e[i].clear(),vis[i]=0;
for(int u,v;m--;)
u=rd(),v=rd(),e[u].pb(v),e[v].pb(u);
for(int i=0;i<2;i++){
for(int j=1;j<=n;j++)w[i][j]=rd();
scanf("%s",s[i]+1);
}
sol();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 32336kb
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: 145ms
memory: 45076kb
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'