QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#620635 | #1869. Power Station of Art | caijianhong | AC ✓ | 262ms | 35912kb | C++20 | 1.8kb | 2024-10-07 19:57:08 | 2024-10-07 19:57:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) (void)fprintf(stderr, ##__VA_ARGS__)
#else
#define endl "\n"
#define debug(...) (void)0
#endif
using LL = long long;
int n, m, w1[1000010], w2[1000010], col[1000010];
char col1[1000010], col2[1000010];
vector<int> g[1000010], V;
bool ef;
void ffl(int u) {
V.push_back(u);
for (int v : g[u]) if (!col[v]) col[v] = 3 - col[u], ffl(v); else if (col[u] != 3 - col[v]) ef = false;
}
int mian() {
cin >> n >> m;
for (int i = 1; i <= n; i++) g[i].clear(), col[i] = 0;
for (int i = 1, u, v; i <= m; i++) cin >> u >> v, g[u].push_back(v), g[v].push_back(u);
for (int i = 1; i <= n; i++) cin >> w1[i];
for (int i = 1; i <= n; i++) cin >> col1[i];
for (int i = 1; i <= n; i++) cin >> w2[i];
for (int i = 1; i <= n; i++) cin >> col2[i];
for (int rt = 1; rt <= n; rt++) if (!col[rt]) {
col[rt] = 1, ef = true, V.clear(), ffl(rt);
if (ef) {
vector<int> lhs, rhs;
for (int i : V) {
lhs.push_back(w1[i] << 1 | ((col[i] == 1) ^ (col1[i] == 'R')));
rhs.push_back(w2[i] << 1 | ((col[i] == 1) ^ (col2[i] == 'R')));
}
sort(lhs.begin(), lhs.end());
sort(rhs.begin(), rhs.end());
if (lhs != rhs) return 0;
} else {
vector<int> lhs, rhs;
int cnt = 0;
for (int i : V) {
lhs.push_back(w1[i]);
if (col1[i] == 'R') cnt ^= 1;
rhs.push_back(w2[i]);
if (col2[i] == 'R') cnt ^= 1;
}
sort(lhs.begin(), lhs.end());
sort(rhs.begin(), rhs.end());
if (lhs != rhs || cnt) return 0;
}
}
return 1;
}
int main() {
#ifndef LOCAL
#ifdef NF
freopen("graph.in", "r", stdin);
freopen("graph.out", "w", stdout);
#endif
cin.tie(nullptr)->sync_with_stdio(false);
#endif
int t;
cin >> t;
while (t--) cout << (mian() ? "YES" : "NO") << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 11808kb
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: 262ms
memory: 35912kb
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