QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#620628 | #1869. Power Station of Art | caijianhong | RE | 0ms | 0kb | C++20 | 1.8kb | 2024-10-07 19:54:51 | 2024-10-07 19:54:53 |
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[100010], w2[100010], col[100010];
char col1[100010], col2[100010];
vector<int> g[100010], 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
#ifndef 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: 0
Dangerous Syscalls
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