#include <bits/stdc++.h>
template <class T>
using Vec = std::vector<T>;
struct DSU {
Vec<int> par;
DSU(const int n): par(n, -1) { }
int find(const int u) {
return par[u] < 0 ? u : par[u] = find(par[u]);
}
void merge(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return;
if (par[x] > par[y]) {
std::swap(x, y);
}
par[x] += par[y];
par[y] = x;
}
};
int main() {
int N, M, Q;
std::cin >> N >> M >> Q;
Vec<int> A(M), B(M);
for (int i = 0; i < M; ++i) {
std::cin >> A[i] >> B[i];
A[i] -= 1;
B[i] -= 1;
}
Vec<int> L(Q), R(Q);
for (int i = 0; i < Q; ++i) {
std::cin >> L[i] >> R[i];
L[i] -= 1;
R[i] -= 1;
}
if (M <= 2000 and Q <= 2000) {
for (int i = 0; i < Q; ++i) {
DSU dsu(2 * N);
for (int j = 0; j < L[i]; ++j) {
dsu.merge(A[j], B[j] + N);
dsu.merge(A[j] + N, B[j]);
}
for (int j = M - 1; j > R[i]; --j) {
dsu.merge(A[j], B[j] + N);
dsu.merge(A[j] + N, B[j]);
}
bool ok = false;
for (int i = 0; i < N; ++i) {
if (dsu.find(i) == dsu.find(i + N)) {
ok = true;
break;
}
}
if (ok) {
std::cout << "YES\n";
}
else {
std::cout << "NO\n";
}
}
return 0;
}
DSU dsu(2 * N);
int border = -1;
for (int i = M - 1; i >= 0; --i) {
dsu.merge(A[i], B[i] + N);
dsu.merge(A[i] + N, B[i]);
if (dsu.find(A[i]) == dsu.find(A[i] + N) or dsu.find(B[i]) == dsu.find(B[i] + N)) {
border = i;
break;
}
}
for (int i = 0; i < Q; ++i) {
if (R[i] < border) {
std::cout << "YES\n";
}
else {
std::cout << "NO\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
2 ms |
204 KB |
Output is correct |
16 |
Correct |
2 ms |
204 KB |
Output is correct |
17 |
Correct |
2 ms |
204 KB |
Output is correct |
18 |
Correct |
2 ms |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
204 KB |
Output is correct |
20 |
Correct |
2 ms |
304 KB |
Output is correct |
21 |
Correct |
2 ms |
204 KB |
Output is correct |
22 |
Correct |
2 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
2 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
2 ms |
204 KB |
Output is correct |
28 |
Correct |
2 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
2 ms |
204 KB |
Output is correct |
16 |
Correct |
2 ms |
204 KB |
Output is correct |
17 |
Correct |
2 ms |
204 KB |
Output is correct |
18 |
Correct |
2 ms |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
204 KB |
Output is correct |
20 |
Correct |
2 ms |
304 KB |
Output is correct |
21 |
Correct |
2 ms |
204 KB |
Output is correct |
22 |
Correct |
2 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
2 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
2 ms |
204 KB |
Output is correct |
28 |
Correct |
2 ms |
204 KB |
Output is correct |
29 |
Correct |
78 ms |
344 KB |
Output is correct |
30 |
Correct |
89 ms |
360 KB |
Output is correct |
31 |
Correct |
89 ms |
332 KB |
Output is correct |
32 |
Correct |
66 ms |
360 KB |
Output is correct |
33 |
Correct |
53 ms |
348 KB |
Output is correct |
34 |
Correct |
78 ms |
364 KB |
Output is correct |
35 |
Correct |
94 ms |
332 KB |
Output is correct |
36 |
Correct |
61 ms |
332 KB |
Output is correct |
37 |
Correct |
106 ms |
356 KB |
Output is correct |
38 |
Correct |
151 ms |
360 KB |
Output is correct |
39 |
Correct |
76 ms |
372 KB |
Output is correct |
40 |
Correct |
65 ms |
352 KB |
Output is correct |
41 |
Correct |
75 ms |
332 KB |
Output is correct |
42 |
Correct |
66 ms |
332 KB |
Output is correct |
43 |
Correct |
82 ms |
352 KB |
Output is correct |
44 |
Correct |
100 ms |
332 KB |
Output is correct |
45 |
Correct |
112 ms |
368 KB |
Output is correct |
46 |
Correct |
115 ms |
380 KB |
Output is correct |
47 |
Correct |
65 ms |
332 KB |
Output is correct |
48 |
Correct |
70 ms |
368 KB |
Output is correct |
49 |
Correct |
77 ms |
332 KB |
Output is correct |
50 |
Correct |
82 ms |
372 KB |
Output is correct |
51 |
Correct |
62 ms |
356 KB |
Output is correct |
52 |
Correct |
74 ms |
332 KB |
Output is correct |
53 |
Correct |
79 ms |
332 KB |
Output is correct |
54 |
Correct |
89 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
237 ms |
4844 KB |
Output is correct |
4 |
Correct |
215 ms |
5576 KB |
Output is correct |
5 |
Correct |
234 ms |
5448 KB |
Output is correct |
6 |
Correct |
241 ms |
4852 KB |
Output is correct |
7 |
Correct |
276 ms |
4828 KB |
Output is correct |
8 |
Correct |
220 ms |
4672 KB |
Output is correct |
9 |
Correct |
207 ms |
4864 KB |
Output is correct |
10 |
Correct |
216 ms |
5728 KB |
Output is correct |
11 |
Correct |
233 ms |
4844 KB |
Output is correct |
12 |
Correct |
256 ms |
5344 KB |
Output is correct |
13 |
Correct |
260 ms |
4300 KB |
Output is correct |
14 |
Correct |
230 ms |
4452 KB |
Output is correct |
15 |
Correct |
235 ms |
5056 KB |
Output is correct |
16 |
Correct |
236 ms |
5596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
2 ms |
204 KB |
Output is correct |
16 |
Correct |
2 ms |
204 KB |
Output is correct |
17 |
Correct |
2 ms |
204 KB |
Output is correct |
18 |
Correct |
2 ms |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
204 KB |
Output is correct |
20 |
Correct |
2 ms |
304 KB |
Output is correct |
21 |
Correct |
2 ms |
204 KB |
Output is correct |
22 |
Correct |
2 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
2 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
2 ms |
204 KB |
Output is correct |
28 |
Correct |
2 ms |
204 KB |
Output is correct |
29 |
Correct |
237 ms |
4844 KB |
Output is correct |
30 |
Correct |
215 ms |
5576 KB |
Output is correct |
31 |
Correct |
234 ms |
5448 KB |
Output is correct |
32 |
Correct |
241 ms |
4852 KB |
Output is correct |
33 |
Correct |
276 ms |
4828 KB |
Output is correct |
34 |
Correct |
220 ms |
4672 KB |
Output is correct |
35 |
Correct |
207 ms |
4864 KB |
Output is correct |
36 |
Correct |
216 ms |
5728 KB |
Output is correct |
37 |
Correct |
233 ms |
4844 KB |
Output is correct |
38 |
Correct |
256 ms |
5344 KB |
Output is correct |
39 |
Correct |
260 ms |
4300 KB |
Output is correct |
40 |
Correct |
230 ms |
4452 KB |
Output is correct |
41 |
Correct |
235 ms |
5056 KB |
Output is correct |
42 |
Correct |
236 ms |
5596 KB |
Output is correct |
43 |
Incorrect |
239 ms |
9136 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
2 ms |
204 KB |
Output is correct |
16 |
Correct |
2 ms |
204 KB |
Output is correct |
17 |
Correct |
2 ms |
204 KB |
Output is correct |
18 |
Correct |
2 ms |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
204 KB |
Output is correct |
20 |
Correct |
2 ms |
304 KB |
Output is correct |
21 |
Correct |
2 ms |
204 KB |
Output is correct |
22 |
Correct |
2 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
2 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
2 ms |
204 KB |
Output is correct |
28 |
Correct |
2 ms |
204 KB |
Output is correct |
29 |
Correct |
78 ms |
344 KB |
Output is correct |
30 |
Correct |
89 ms |
360 KB |
Output is correct |
31 |
Correct |
89 ms |
332 KB |
Output is correct |
32 |
Correct |
66 ms |
360 KB |
Output is correct |
33 |
Correct |
53 ms |
348 KB |
Output is correct |
34 |
Correct |
78 ms |
364 KB |
Output is correct |
35 |
Correct |
94 ms |
332 KB |
Output is correct |
36 |
Correct |
61 ms |
332 KB |
Output is correct |
37 |
Correct |
106 ms |
356 KB |
Output is correct |
38 |
Correct |
151 ms |
360 KB |
Output is correct |
39 |
Correct |
76 ms |
372 KB |
Output is correct |
40 |
Correct |
65 ms |
352 KB |
Output is correct |
41 |
Correct |
75 ms |
332 KB |
Output is correct |
42 |
Correct |
66 ms |
332 KB |
Output is correct |
43 |
Correct |
82 ms |
352 KB |
Output is correct |
44 |
Correct |
100 ms |
332 KB |
Output is correct |
45 |
Correct |
112 ms |
368 KB |
Output is correct |
46 |
Correct |
115 ms |
380 KB |
Output is correct |
47 |
Correct |
65 ms |
332 KB |
Output is correct |
48 |
Correct |
70 ms |
368 KB |
Output is correct |
49 |
Correct |
77 ms |
332 KB |
Output is correct |
50 |
Correct |
82 ms |
372 KB |
Output is correct |
51 |
Correct |
62 ms |
356 KB |
Output is correct |
52 |
Correct |
74 ms |
332 KB |
Output is correct |
53 |
Correct |
79 ms |
332 KB |
Output is correct |
54 |
Correct |
89 ms |
364 KB |
Output is correct |
55 |
Incorrect |
129 ms |
5084 KB |
Output isn't correct |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
2 ms |
204 KB |
Output is correct |
16 |
Correct |
2 ms |
204 KB |
Output is correct |
17 |
Correct |
2 ms |
204 KB |
Output is correct |
18 |
Correct |
2 ms |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
204 KB |
Output is correct |
20 |
Correct |
2 ms |
304 KB |
Output is correct |
21 |
Correct |
2 ms |
204 KB |
Output is correct |
22 |
Correct |
2 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
2 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
2 ms |
204 KB |
Output is correct |
28 |
Correct |
2 ms |
204 KB |
Output is correct |
29 |
Correct |
78 ms |
344 KB |
Output is correct |
30 |
Correct |
89 ms |
360 KB |
Output is correct |
31 |
Correct |
89 ms |
332 KB |
Output is correct |
32 |
Correct |
66 ms |
360 KB |
Output is correct |
33 |
Correct |
53 ms |
348 KB |
Output is correct |
34 |
Correct |
78 ms |
364 KB |
Output is correct |
35 |
Correct |
94 ms |
332 KB |
Output is correct |
36 |
Correct |
61 ms |
332 KB |
Output is correct |
37 |
Correct |
106 ms |
356 KB |
Output is correct |
38 |
Correct |
151 ms |
360 KB |
Output is correct |
39 |
Correct |
76 ms |
372 KB |
Output is correct |
40 |
Correct |
65 ms |
352 KB |
Output is correct |
41 |
Correct |
75 ms |
332 KB |
Output is correct |
42 |
Correct |
66 ms |
332 KB |
Output is correct |
43 |
Correct |
82 ms |
352 KB |
Output is correct |
44 |
Correct |
100 ms |
332 KB |
Output is correct |
45 |
Correct |
112 ms |
368 KB |
Output is correct |
46 |
Correct |
115 ms |
380 KB |
Output is correct |
47 |
Correct |
65 ms |
332 KB |
Output is correct |
48 |
Correct |
70 ms |
368 KB |
Output is correct |
49 |
Correct |
77 ms |
332 KB |
Output is correct |
50 |
Correct |
82 ms |
372 KB |
Output is correct |
51 |
Correct |
62 ms |
356 KB |
Output is correct |
52 |
Correct |
74 ms |
332 KB |
Output is correct |
53 |
Correct |
79 ms |
332 KB |
Output is correct |
54 |
Correct |
89 ms |
364 KB |
Output is correct |
55 |
Correct |
237 ms |
4844 KB |
Output is correct |
56 |
Correct |
215 ms |
5576 KB |
Output is correct |
57 |
Correct |
234 ms |
5448 KB |
Output is correct |
58 |
Correct |
241 ms |
4852 KB |
Output is correct |
59 |
Correct |
276 ms |
4828 KB |
Output is correct |
60 |
Correct |
220 ms |
4672 KB |
Output is correct |
61 |
Correct |
207 ms |
4864 KB |
Output is correct |
62 |
Correct |
216 ms |
5728 KB |
Output is correct |
63 |
Correct |
233 ms |
4844 KB |
Output is correct |
64 |
Correct |
256 ms |
5344 KB |
Output is correct |
65 |
Correct |
260 ms |
4300 KB |
Output is correct |
66 |
Correct |
230 ms |
4452 KB |
Output is correct |
67 |
Correct |
235 ms |
5056 KB |
Output is correct |
68 |
Correct |
236 ms |
5596 KB |
Output is correct |
69 |
Incorrect |
239 ms |
9136 KB |
Output isn't correct |
70 |
Halted |
0 ms |
0 KB |
- |