QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#618039 | #1869. Power Station of Art | Tx_Lcy | AC ✓ | 224ms | 47620kb | C++14 | 1.3kb | 2024-10-06 18:14:59 | 2024-10-06 18:15:03 |
Judging History
answer
//A tree without skin will surely die.
//A man without face will be alive.
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
int const N=1e6+10;
int n,m,a[N],b[N],co[N],G;
string A,B;vector<int>e[N];
inline bool g(char X){return (X=='R');}
vector< pair<int,int> >v1,v2;
inline void dfs(int x,int Co,int &co1,int &co2){
co1^=g(A[x]),co2^=g(B[x]),co[x]=Co;
v1.push_back({a[x],Co^g(A[x])}),v2.push_back({b[x],Co^g(B[x])});
for (auto v:e[x])
if (co[v]==-1){
dfs(v,Co^1,co1,co2);
}else if (co[v]==Co) G=1;
}
inline void solve(){
cin>>n>>m;
rep(i,1,n) co[i]=-1,e[i].clear();
rep(i,1,m){
int u,v;cin>>u>>v;
e[u].push_back(v);
e[v].push_back(u);
}
rep(i,1,n) cin>>a[i];
cin>>A,A=" "+A;
rep(i,1,n) cin>>b[i];
cin>>B,B=" "+B;
rep(i,1,n){
if (co[i]!=-1) continue;
int co1=0,co2=0;
G=0,v1.clear(),v2.clear(),dfs(i,0,co1,co2);
if (co1!=co2) return cout<<"NO\n",void();
sort(all(v1)),sort(all(v2));
if (!G && v1!=v2) return cout<<"NO\n",void();
int sz=v1.size();
rep(j,0,sz-1)
if (v1[j].first!=v2[j].first) return cout<<"NO\n",void();
}
cout<<"YES\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=1;
cin>>t;
while (t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 33088kb
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: 224ms
memory: 47620kb
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