QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#583722 | #1869. Power Station of Art | XSC062 | AC ✓ | 340ms | 20088kb | C++14 | 3.5kb | 2024-09-22 21:35:24 | 2024-09-22 21:35:25 |
Judging History
answer
#include <bits/stdc++.h>
int main() {
#ifdef ONLINE_JUDGE
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
#else
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
int T;
for (std::cin >> T; T--; ) {
int n, m;
std::cin >> n >> m;
std::vector<std::vector<int> > g(n + 1);
std::vector<int> col(n + 1), a(n + 1), b(n + 1), s(n + 1), t(n + 1);
for (int x, y; m--; ) {
std::cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
for (int i = 1; i <= n; ++i)
std::cin >> a[i];
for (int i = 1; i <= n; ++i) {
char c;
std::cin >> c;
s[i] = (c == 'R');
}
for (int i = 1; i <= n; ++i)
std::cin >> b[i];
for (int i = 1; i <= n; ++i) {
char c;
std::cin >> c;
t[i] = (c == 'R');
}
std::vector<int> p;
std::function<bool(int, int)> DFS = [&](int x, int c) {
p.push_back(x);
col[x] = c;
bool flag = 1;
for (auto i : g[x]) {
if (!col[i])
flag &= DFS(i, 3 - c);
else if (col[i] == c)
flag = 0;
}
return flag;
};
for (int i = 1; i <= n; ++i)
if (!col[i]) {
p.clear();
if (DFS(i, 1)) {
struct _ { int a10, a11, a20, a21, b10, b11, b20, b21; };
std::unordered_map<int, _> l;
for (auto j : p) {
l[a[j]].a10 += (col[j] == 1 && s[j] == 0);
l[a[j]].a11 += (col[j] == 1 && s[j] == 1);
l[a[j]].a20 += (col[j] == 2 && s[j] == 0);
l[a[j]].a21 += (col[j] == 2 && s[j] == 1);
l[b[j]].b10 += (col[j] == 1 && t[j] == 0);
l[b[j]].b11 += (col[j] == 1 && t[j] == 1);
l[b[j]].b20 += (col[j] == 2 && t[j] == 0);
l[b[j]].b21 += (col[j] == 2 && t[j] == 1);
}
for (auto j : l) {
_ t = j.second;
if (t.a10 + t.a21 != t.b10 + t.b21 ||
t.a11 + t.a20 != t.b11 + t.b20) {
std::cout << "NO\n";
goto nosol;
}
}
}
else {
int a0 = 0, a1 = 0, b0 = 0, b1 = 0;
std::map<int, std::pair<int, int> > l;
for (auto j : p) {
a0 += (s[j] == 0);
a1 += (s[j] == 1);
b0 += (t[j] == 0);
b1 += (t[j] == 1);
++l[a[j]].first;
++l[b[j]].second;
}
if (((a0 ^ b0) & 1) || ((a1 ^ b1) & 1)) {
std::cout << "NO\n";
goto nosol;
}
for (auto j : l)
if (j.second.first != j.second.second) {
std::cout << "NO\n";
goto nosol;
}
}
}
std::cout << "YES\n";
nosol: ;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3844kb
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: 340ms
memory: 20088kb
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