QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#617952 | #1869. Power Station of Art | Milkcat2009 | AC ✓ | 244ms | 75456kb | C++14 | 1.9kb | 2024-10-06 17:51:43 | 2024-10-06 17:51:44 |
Judging History
answer
#include <bits/stdc++.h>
#define REP(i, l, r) for (int i = (l); i <= (r); ++ i)
#define DEP(i, r, l) for (int i = (r); i >= (l); -- i)
#define fi first
#define se second
#define pb emplace_back
#define mems(x, v) memset((x), (v), sizeof(x))
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
using namespace std;
namespace Milkcat {
typedef long long LL;
typedef pair<LL, LL> pii;
const int N = 2e6 + 5;
int n, m, u, v, chk, a[N], b[N], A[N], B[N], c[N], vs[N]; vector<int> s, G[N]; char x;
void color(int u, int& chk) {
s.pb(u);
for (int v : G[u]) {
if (c[v] < 0) c[v] = c[u] ^ 1, color(v, chk);
else chk &= (c[u] != c[v]);
}
}
int W(int x, int t) {
return (t ? A[x] : a[x]) + (t ? B[x] ^ c[x] : b[x] ^ c[x]) * 1e6;
}
int main() {
cin >> n >> m, chk = 1;
REP(i, 1, m) cin >> u >> v, G[u].pb(v), G[v].pb(u);
REP(i, 1, n) cin >> a[i];
REP(i, 1, n) cin >> x, b[i] = (x == 'R');
REP(i, 1, n) cin >> A[i], c[i] = -1;
REP(i, 1, n) cin >> x, B[i] = (x == 'R');
REP(i, 1, n) {
if (c[i] != -1) continue;
int bip = 1, ct = 0;
c[i] = 0, s.clear(), color(i, bip);
if (bip) {
for (int x : s) {
int p = W(x, 0), q = W(x, 1);
if (!vs[p] ++) ct ++;
if (!-- vs[q]) ct --;
}
chk &= !ct;
for (int x : s)
vs[W(x, 0)] = vs[W(x, 1)] = 0;
} else {
int P = 0;
for (int x : s) {
if (!vs[a[x]] ++) ct ++;
if (!-- vs[A[x]]) ct --;
P ^= b[x] ^ B[x];
}
chk &= (!ct && !P);
for (int x : s)
vs[a[x]] = vs[A[x]] = 0;
}
}
cout << (chk ? "YES" : "NO") << '\n';
REP(i, 1, n) G[i].clear();
return 0;
}
}
int main() {
// freopen("graph.in", "r", stdin);
// freopen("graph.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T = 1; cin >> T;
while (T --) Milkcat::main();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 61936kb
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: 244ms
memory: 75456kb
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