QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#617719#1869. Power Station of ArtMilkcat2009WA 243ms78172kbC++142.0kb2024-10-06 16:45:222024-10-06 16:45:23

Judging History

你现在查看的是最新测评结果

  • [2024-10-06 16:45:23]
  • 评测
  • 测评结果:WA
  • 用时:243ms
  • 内存:78172kb
  • [2024-10-06 16:45:22]
  • 提交

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], r[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, Q = 0;
				for (int x : s) {
					if (!vs[a[x]] ++) ct ++;
					if (!-- vs[A[x]]) ct --;
					ct -= r[a[x]], ct -= r[A[x]];
					r[a[x]] ^= b[x], r[A[x]] ^= B[x];
					ct += r[a[x]], ct += r[A[x]];
				}
				chk &= !ct;
				for (int x : s)
					vs[a[x]] = vs[A[x]] = r[a[x]] = r[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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 60868kb

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: -100
Wrong Answer
time: 243ms
memory: 78172kb

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:

NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES
NO
NO
YES
YES
YES
NO
YES
NO
YES
NO
NO
YES
YES
NO
YES
NO
NO
YES
YES
NO
NO
NO
YES
NO
NO
NO
YES
YES
NO
NO
YES
NO
NO
YES
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
YES
NO
YES
YES
YES
YES
YES
NO
NO
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
NO
NO
NO
NO
NO
YES
NO
NO
YE...

result:

wrong answer 1st lines differ - expected: 'YES', found: 'NO'