QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#616630#1869. Power Station of Artcyj888RE 0ms6024kbC++111.8kb2024-10-06 09:24:322024-10-06 09:24:33

Judging History

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

  • [2024-10-06 09:24:33]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:6024kb
  • [2024-10-06 09:24:32]
  • 提交

answer

#include <bits/stdc++.h>
//#define int long long
#define fi first
#define se second
#define pb push_back
#define ott(i, l, r) for (int i = (l); i <= (r); i ++)
#define tto(i, l, r) for (int i = (r); i >= (l); i --)
int read () {
	int x = 0; bool f = 0; char c = getchar ();
	while (!isdigit (c)) f |= (c == '-'), c = getchar ();
	while (isdigit (c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar ();
	if (f) x = -x; return x;
}
using namespace std;
using ll = long long;
const int N = 1e5 + 110, mod = 1e9 + 7, inf = 0x3f3f3f3f;
int T, n, m; bool res;
int a[N], b[N], col[N], c1[2], c2[2]; bool c[N], d[N];
vector <int> e[N];
vector <pair <int, int>> A, B;
bool dfs (int u) {
	A.emplace_back (a[u], c[u] ^ col[u]), B.emplace_back (b[u], d[u] ^ col[u]);
	bool fl = 1; ++ c1[c[u]], ++ c2[d[u]];
	for (int v : e[u]) {
		if (!~col[v]) col[v] = col[u] ^ 1, fl &= dfs (v);
		else if (!(col[v] ^ col[u])) fl = 0;
	}
	return fl;
}
void sol () {
	res = 1, n = read (), m = read (); while (m --) {
		int x = read (), y = read ();
		e[x].pb (y), e[y].pb (x);
	}
	ott (i, 1, n) a[i] = read (); ott (i, 1, n) c[i] = getchar () == 'R';
	ott (i, 1, n) b[i] = read (); ott (i, 1, n) d[i] = getchar () == 'R';
	fill (col + 1, col + 1 + n, -1);
	ott (i, 1, n) {
		if (!~col[i]) {
			col[i] = 0, c1[0] = c2[0] = c1[1] = c2[1] = 0;
			bool fl = dfs (i); sort (A.begin (), A.end ()), sort (B.begin (), B.end ());
			if (fl)
				ott (i, 0, A.size () - 1)
				    fl &= (A[i] == B[i]);
			else {
				fl = !((c1[0] ^ c2[0]) & 1);
				ott (i, 0, A.size () - 1)
				    fl &= (A[i].fi == B[i].fi);
			}
			res &= fl, A.clear (), B.clear ();
		}
	}
	puts (res ? "YES" : "NO");
	ott (i, 1, n) e[i].clear ();
    return ;
}
int main () {
	T = read (); while (T --) sol ();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 6024kb

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
Runtime Error

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: