#include <bits/stdc++.h>
using namespace std;
const int N = 200'000 + 10;
int n, m, q;
struct Edge {
int u, v;
friend istream& operator >> (istream& is, auto& rhs) {
return is >> rhs.u >> rhs.v;
}
} edge[N];
struct DSU {
int id[N], co[N], cnt;
bool mk[N];
void clear() {
memset(id, -1, (n + 1) * sizeof(int));
memset(co, 0, (n + 1) * sizeof(int));
memset(mk, false, (n + 1) * sizeof(int));
cnt = 0;
}
int root(int u) { return id[u] < 0 ? u : root(id[u]); }
bool chk(int u) { return id[u] < 0 ? mk[u] : mk[u] ^ chk(id[u]); }
inline int color(int u) { return co[u] ^ chk(u); }
void add(int u, int v) {
int oU = u, oV = v;
u = root(u); v = root(v);
if (u == v) { cnt += color(oU) == color(oV); return; }
if (id[u] > id[v]) swap(u, v);
if (color(oU) == color(oV)) mk[v] ^= 1;
id[u] += id[v];
id[v] = u;
}
} T;
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> q;
for (int i = 1; i <= m; ++i) cin >> edge[i];
while (q--) {
int l, r; cin >> l >> r;
T.clear();
for (int i = 1; i < l; ++i) T.add(edge[i].u, edge[i].v);
for (int i = m; i > r; --i) T.add(edge[i].u, edge[i].v);
cout << (T.cnt ? "YES" : "NO") << "\n";
}
}
Compilation message
Joker.cpp:9:45: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
9 | friend istream& operator >> (istream& is, auto& rhs) {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2512 KB |
Output is correct |
5 |
Correct |
0 ms |
2512 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2420 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
0 ms |
2396 KB |
Output is correct |
24 |
Correct |
0 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2392 KB |
Output is correct |
27 |
Correct |
0 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2512 KB |
Output is correct |
5 |
Correct |
0 ms |
2512 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2420 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
0 ms |
2396 KB |
Output is correct |
24 |
Correct |
0 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2392 KB |
Output is correct |
27 |
Correct |
0 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
8 ms |
2396 KB |
Output is correct |
30 |
Correct |
19 ms |
2396 KB |
Output is correct |
31 |
Correct |
19 ms |
2396 KB |
Output is correct |
32 |
Correct |
17 ms |
2560 KB |
Output is correct |
33 |
Correct |
17 ms |
2396 KB |
Output is correct |
34 |
Correct |
17 ms |
2396 KB |
Output is correct |
35 |
Correct |
21 ms |
2560 KB |
Output is correct |
36 |
Correct |
10 ms |
2396 KB |
Output is correct |
37 |
Correct |
15 ms |
2652 KB |
Output is correct |
38 |
Correct |
20 ms |
2396 KB |
Output is correct |
39 |
Correct |
12 ms |
2396 KB |
Output is correct |
40 |
Correct |
15 ms |
2552 KB |
Output is correct |
41 |
Correct |
15 ms |
2392 KB |
Output is correct |
42 |
Correct |
15 ms |
2396 KB |
Output is correct |
43 |
Correct |
34 ms |
2556 KB |
Output is correct |
44 |
Correct |
38 ms |
2396 KB |
Output is correct |
45 |
Correct |
40 ms |
2396 KB |
Output is correct |
46 |
Correct |
39 ms |
2396 KB |
Output is correct |
47 |
Correct |
15 ms |
2392 KB |
Output is correct |
48 |
Correct |
16 ms |
2396 KB |
Output is correct |
49 |
Correct |
16 ms |
2396 KB |
Output is correct |
50 |
Correct |
15 ms |
2396 KB |
Output is correct |
51 |
Correct |
17 ms |
2556 KB |
Output is correct |
52 |
Correct |
18 ms |
2396 KB |
Output is correct |
53 |
Correct |
17 ms |
2396 KB |
Output is correct |
54 |
Correct |
18 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Runtime error |
19 ms |
9820 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2512 KB |
Output is correct |
5 |
Correct |
0 ms |
2512 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2420 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
0 ms |
2396 KB |
Output is correct |
24 |
Correct |
0 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2392 KB |
Output is correct |
27 |
Correct |
0 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Runtime error |
19 ms |
9820 KB |
Execution killed with signal 6 |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2512 KB |
Output is correct |
5 |
Correct |
0 ms |
2512 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2420 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
0 ms |
2396 KB |
Output is correct |
24 |
Correct |
0 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2392 KB |
Output is correct |
27 |
Correct |
0 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
8 ms |
2396 KB |
Output is correct |
30 |
Correct |
19 ms |
2396 KB |
Output is correct |
31 |
Correct |
19 ms |
2396 KB |
Output is correct |
32 |
Correct |
17 ms |
2560 KB |
Output is correct |
33 |
Correct |
17 ms |
2396 KB |
Output is correct |
34 |
Correct |
17 ms |
2396 KB |
Output is correct |
35 |
Correct |
21 ms |
2560 KB |
Output is correct |
36 |
Correct |
10 ms |
2396 KB |
Output is correct |
37 |
Correct |
15 ms |
2652 KB |
Output is correct |
38 |
Correct |
20 ms |
2396 KB |
Output is correct |
39 |
Correct |
12 ms |
2396 KB |
Output is correct |
40 |
Correct |
15 ms |
2552 KB |
Output is correct |
41 |
Correct |
15 ms |
2392 KB |
Output is correct |
42 |
Correct |
15 ms |
2396 KB |
Output is correct |
43 |
Correct |
34 ms |
2556 KB |
Output is correct |
44 |
Correct |
38 ms |
2396 KB |
Output is correct |
45 |
Correct |
40 ms |
2396 KB |
Output is correct |
46 |
Correct |
39 ms |
2396 KB |
Output is correct |
47 |
Correct |
15 ms |
2392 KB |
Output is correct |
48 |
Correct |
16 ms |
2396 KB |
Output is correct |
49 |
Correct |
16 ms |
2396 KB |
Output is correct |
50 |
Correct |
15 ms |
2396 KB |
Output is correct |
51 |
Correct |
17 ms |
2556 KB |
Output is correct |
52 |
Correct |
18 ms |
2396 KB |
Output is correct |
53 |
Correct |
17 ms |
2396 KB |
Output is correct |
54 |
Correct |
18 ms |
2396 KB |
Output is correct |
55 |
Runtime error |
20 ms |
9556 KB |
Execution killed with signal 6 |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2512 KB |
Output is correct |
5 |
Correct |
0 ms |
2512 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2420 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
0 ms |
2396 KB |
Output is correct |
24 |
Correct |
0 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2392 KB |
Output is correct |
27 |
Correct |
0 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
8 ms |
2396 KB |
Output is correct |
30 |
Correct |
19 ms |
2396 KB |
Output is correct |
31 |
Correct |
19 ms |
2396 KB |
Output is correct |
32 |
Correct |
17 ms |
2560 KB |
Output is correct |
33 |
Correct |
17 ms |
2396 KB |
Output is correct |
34 |
Correct |
17 ms |
2396 KB |
Output is correct |
35 |
Correct |
21 ms |
2560 KB |
Output is correct |
36 |
Correct |
10 ms |
2396 KB |
Output is correct |
37 |
Correct |
15 ms |
2652 KB |
Output is correct |
38 |
Correct |
20 ms |
2396 KB |
Output is correct |
39 |
Correct |
12 ms |
2396 KB |
Output is correct |
40 |
Correct |
15 ms |
2552 KB |
Output is correct |
41 |
Correct |
15 ms |
2392 KB |
Output is correct |
42 |
Correct |
15 ms |
2396 KB |
Output is correct |
43 |
Correct |
34 ms |
2556 KB |
Output is correct |
44 |
Correct |
38 ms |
2396 KB |
Output is correct |
45 |
Correct |
40 ms |
2396 KB |
Output is correct |
46 |
Correct |
39 ms |
2396 KB |
Output is correct |
47 |
Correct |
15 ms |
2392 KB |
Output is correct |
48 |
Correct |
16 ms |
2396 KB |
Output is correct |
49 |
Correct |
16 ms |
2396 KB |
Output is correct |
50 |
Correct |
15 ms |
2396 KB |
Output is correct |
51 |
Correct |
17 ms |
2556 KB |
Output is correct |
52 |
Correct |
18 ms |
2396 KB |
Output is correct |
53 |
Correct |
17 ms |
2396 KB |
Output is correct |
54 |
Correct |
18 ms |
2396 KB |
Output is correct |
55 |
Runtime error |
19 ms |
9820 KB |
Execution killed with signal 6 |
56 |
Halted |
0 ms |
0 KB |
- |