QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#260132 | #1869. Power Station of Art | Dualqwq | AC ✓ | 680ms | 43428kb | C++20 | 1.5kb | 2023-11-21 20:51:05 | 2023-11-21 20:51:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5,Lim = 1e6 + 1;
int n,m;
int A[N],B[N],ac[N],bc[N];
int vst[N];
bool FLG = false;
map<int,int> mp1,mp2;
int num_c;
int fir[N],nxt[N << 1],to[N << 1],ect = 1;
inline void addedge(int u1,int v1) {
nxt[++ect] = fir[u1];fir[u1] = ect;to[ect] = v1;
}
int co[N];
void dfs(int x,int col) {
vst[x] = true;
mp1[(col ^ ac[x]) * Lim + A[x]]++;
mp1[(col ^ bc[x]) * Lim + B[x]]--;
mp2[A[x]]++;mp2[B[x]]--;
num_c += ac[x];num_c -= bc[x];
co[x] = col;
for(int i = fir[x],y;y = to[i],i;i = nxt[i])
if(!vst[y]) dfs(y,col ^ 1);
else if(co[y] == co[x]) FLG = true;
}
inline void work() {
ect = 1;
for(int i = 1;i <= n;i++) fir[i] = vst[i] = co[i] = 0;
cin >> n >> m;
for(int i = 1,u,v;i <= m;i++)
cin >> u >> v,addedge(u,v),addedge(v,u);
for(int i = 1;i <= n;i++) cin >> A[i];
string str;
cin >> str;
for(int i = 1;i <= n;i++) ac[i] = str[i - 1] == 'R';
for(int i = 1;i <= n;i++) cin >> B[i];
cin >> str;
for(int i = 1;i <= n;i++) bc[i] = str[i - 1] == 'R';
for(int i = 1;i <= n;i++) if(!vst[i]) {
FLG = false;num_c = 0;
mp1.clear();mp2.clear();
dfs(i,0);
if(FLG) {
if((num_c & 1)) return puts("NO"),void();
for(auto it : mp2) if(it.second != 0) return puts("NO"),void();
} else {
// printf("mp1: ");
// for(auto it : mp1) printf("(%d,%d) ",it.first,it.second);printf("\n");
for(auto it : mp1) if(it.second != 0) return puts("NO"),void();
}
}
puts("YES");
}
int main() {
int T;
cin >> T;
while(T--) work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 17736kb
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: 680ms
memory: 43428kb
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