QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#60547#1869. Power Station of Art12345678WA 314ms103376kbC++143.1kb2022-11-05 14:42:522022-11-05 14:42:53

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-05 14:42:53]
  • 评测
  • 测评结果:WA
  • 用时:314ms
  • 内存:103376kb
  • [2022-11-05 14:42:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define inf 1e9
#define pii pair <int, int>
const int mod = 1e9 + 7;
int read () {
	int x = 0, f = 1;
	char ch = getchar ();
	while (ch < '0' || ch > '9') f = ((ch == '-') ? -1 : f), ch = getchar ();
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar ();
	return x * f;
}
void write (int x) {
	if (x < 0) x = -x, putchar ('-');
	if (x >= 10) write (x / 10);
	putchar (x % 10 + '0');
}
int quickmod (int x, int y) {
	int Ans = 1;
	while (y) {
		if (y & 1) Ans = (Ans * x) % mod;
		x = (x * x) % mod;
		y >>= 1;
	}
	return Ans;
}
struct UnionSet {
	int fa[1000005];
	void makeSet(int x) {
		for(int i = 1; i <= x; i++) fa[i] = i;
	}
	int findSet(int x) {
		if(x == fa[x]) return x;
		fa[x] = findSet(fa[x]);
		return fa[x];
	}
	void unionSet(int x, int y) {
		x = findSet(x), y = findSet(y);
		if(x == y) return ;
		fa[x] = y;
	}
}U;
int n, m;
int a[1000005], b[1000005];
char cha[1000005], chb[1000005];
vector <int> G[1000005], V[1000005];
int col[1000005], vis[1000005];
void get_col(int x) {
	for(auto y : G[x]) {
		if(col[y]) {
			if(!col[x]) col[x] = 3 - col[y];
			else if(col[x] + col[y] != 3) vis[x] = 1;
		} 
	}
	if(!col[x]) col[x] = 1;
	for(auto y : G[x]) if(!col[y]) get_col(y);
}
int pa[1000005], pb[1000005]; 
int ch1(int id) {//�Ƕ���ͼ
	int cnta = 0, cntb = 0, s = 0;
	for(auto x : V[id]) pa[++cnta] = a[x], pb[++cntb] = b[x], s += (cha[x] == 'R') + (chb[x] == 'R');
	sort(pa + 1, pa + 1 + cnta), sort(pb + 1, pb + 1 + cntb);
	for(int i = 1; i <= cnta; i++) if(pa[i] != pb[i]) return 0;
	return !(s & 1);
}
int ch2(int id) {//����ͼ
	int cnta = 0, cntb = 0, s = 0;
	for(auto x : V[id]) pa[++cnta] = a[x], pb[++cntb] = b[x], s += (cha[x] == 'R') + (chb[x] == 'R');
	sort(pa + 1, pa + 1 + cnta), sort(pb + 1, pb + 1 + cntb);
	for(int i = 1; i <= cnta; i++) if(pa[i] != pb[i]) return 0;
	if(s & 1) return 0;
	int sa1 = 0, sa2 = 0, sb1 = 0, sb2 = 0;
	for(auto x : V[id]) {
		if(col[x] == 1) sa1 += (cha[x] == 'R'), sb1 += (chb[x] == 'R');
		else sa2 += (cha[x] == 'R'), sb2 += (chb[x] == 'R');
	}
	return (sa1 - sa2 == sb1 - sb2);
}
signed main () {
	// freopen ("graph.in", "r", stdin);
	// freopen ("graph.out", "w", stdout);
	int T = read();
	while(T--) {
		n = read(), m = read();
		for(int i = 1; i <= n; i++) G[i].clear(), V[i].clear(), col[i] = vis[i] = 0;
		U.makeSet(n);
		for(int i = 1; i <= m; i++) {
			int u = read(), v = read();
			G[u].push_back(v);
			G[v].push_back(u);
			U.unionSet(u, v);
		}
		for(int i = 1; i <= n; i++) a[i] = read();
		scanf("%s", cha + 1);
		for(int i = 1; i <= n; i++) b[i] = read();
		scanf("%s", chb + 1);
		for(int i = 1; i <= n; i++) if(!col[i]) get_col(i);
		for(int i = 1; i <= n; i++) {
			V[U.findSet(i)].push_back(i); 
			if(vis[i]) vis[U.findSet(i)] = 1;
		}
		int fl = 1;
		for(int i = 1; i <= n; i++) {
			if(U.findSet(i) == i) {
				if(vis[i]) fl &= ch1(i);
				else fl &= ch2(i); 
			}
		}
		if(fl) puts("YES");
		else puts("NO");
	}
	return 0;
}
/*
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 64856kb

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: 314ms
memory: 103376kb

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:

wrong answer 299th lines differ - expected: 'NO', found: 'YES'