QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#840077 | #1869. Power Station of Art | liyujia | AC ✓ | 687ms | 34444kb | C++17 | 1.3kb | 2025-01-02 15:23:13 | 2025-01-02 15:23:20 |
Judging History
answer
#include <bits/stdc++.h>
#define F for(int i = 1; i <= n; i++)
#define S(p) sort(p.begin(), p.end())
using namespace std;
const int N = 500005;
int T, n, m, fcl, cnt1, cnt2, a[N], b[N], vis[N], cl[N];
vector <int> e[N], p, q, v1[2], v2[2];
char c1[N], c2[N];
void dfs(int x){
p.push_back(a[x]), q.push_back(b[x]);
v1[(c1[x] == 'R') ^ cl[x]].push_back(a[x]), v2[(c2[x] == 'R') ^ cl[x]].push_back(b[x]);
vis[x] = 1, cnt1 += c1[x] == 'R', cnt2 += c2[x] == 'R';
for(int i: e[x]) if(!vis[i]) cl[i] = cl[x] ^ 1, dfs(i);
else if(cl[i] == cl[x]) fcl = 1;
}
int solve(int x){
for(int i: {0, 1}) v1[i].clear(), v2[i].clear();
p.clear(), q.clear(), cl[x] = cnt1 = cnt2 = fcl = 0, dfs(x); S(p), S(q);
for(int i = 0; i < p.size(); i++) if(p[i] != q[i]) return 0;
if(fcl) return !(cnt1 - cnt2 & 1);
for(int i: {0, 1}){
S(v1[i]), S(v2[i]);
if(v1[i].size() != v2[i].size()) return 0;
for(int j = 0; j < v1[i].size(); j++) if(v1[i][j] != v2[i][j]) return 0;
}
return 1;
}
int main(){
cin >> T;
while(T--){
cin >> n >> m; int fl = 1;
F e[i].clear(), vis[i] = 0;
for(int i = 1, u, v; i <= m; i++) cin >> u >> v, e[u].push_back(v), e[v].push_back(u);
F cin >> a[i];
F cin >> c1[i];
F cin >> b[i];
F cin >> c2[i];
F if(!vis[i]) fl &= solve(i);
cout << (fl? "YES\n": "NO\n");
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 5ms
memory: 22128kb
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: 687ms
memory: 34444kb
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