#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
int n, m, q, vis_nq[N], par[N], col[N];
vector<pair<int, int>> g[N], atl[N];
pair<int, int> edge[N];
vector<int> S[N];
bool ans[N];
int root(int v){
return (par[v] == -1 ? v : par[v] = root(par[v]));
}
inline bool merge(int u, int v){
int r1 = root(u);
int r2 = root(v);
if (r1 == r2)
return (col[u] != col[v]);
if (S[r2].size() > S[r1].size())
swap(r1, r2);
int take = 0;
if (col[u] == col[v])
take = 3;
for (int x : S[r2]){
col[x] ^= take;
S[r1].push_back(x);
par[x] = r1;
}
S[r2].clear();
return 1;
}
int main(){
scanf("%d%d%d", &n, &m, &q);
for (int i = 1; i <= m; i ++){
int u, v;
scanf("%d%d", &u, &v);
g[u].push_back({i, v});
g[v].push_back({i, u});
edge[i] = {u, v};
}
int mx = 0;
for (int i = 0; i < q; i ++){
int l, r;
scanf("%d%d", &l, &r);
mx = max(mx, l);
atl[l].push_back({r, i});
}
for (int i = 1; i <= mx; i ++){
if (atl[i].size() < 2) continue;
sort(atl[i].begin(), atl[i].end());
reverse(atl[i].begin(), atl[i].end());
}
for (int i = 1; i <= mx; i ++){
if (atl[i].size() == 0) continue;
for (int j = 1; j <= n; j ++){
S[j].clear();
S[j].push_back(j);
par[j] = -1;
col[j] = 1;
}
bool even = 1;
for (int j = 1; j < i; j ++)
even &= merge(edge[j].first, edge[j].second);
int x = m;
for (auto [r, id] : atl[i]){
for (int j = r + 1; j <= x; j ++)
even &= merge(edge[j].first, edge[j].second);
x = r;
if (even)
ans[id] = 0;
else
ans[id] = 1;
}
}
for (int i = 0; i < q; i ++){
if (ans[i])
printf("YES\n");
else
printf("NO\n");
}
}
Compilation message
Joker.cpp: In function 'int main()':
Joker.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%d%d%d", &n, &m, &q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d%d", &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~
Joker.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | scanf("%d%d", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
16732 KB |
Output is correct |
2 |
Correct |
4 ms |
16732 KB |
Output is correct |
3 |
Correct |
4 ms |
16728 KB |
Output is correct |
4 |
Correct |
4 ms |
16840 KB |
Output is correct |
5 |
Correct |
4 ms |
16732 KB |
Output is correct |
6 |
Correct |
4 ms |
16732 KB |
Output is correct |
7 |
Correct |
4 ms |
16828 KB |
Output is correct |
8 |
Correct |
4 ms |
16732 KB |
Output is correct |
9 |
Correct |
4 ms |
16732 KB |
Output is correct |
10 |
Correct |
5 ms |
16732 KB |
Output is correct |
11 |
Correct |
6 ms |
16732 KB |
Output is correct |
12 |
Correct |
4 ms |
16732 KB |
Output is correct |
13 |
Correct |
5 ms |
16732 KB |
Output is correct |
14 |
Correct |
4 ms |
16732 KB |
Output is correct |
15 |
Correct |
4 ms |
16732 KB |
Output is correct |
16 |
Correct |
4 ms |
16732 KB |
Output is correct |
17 |
Correct |
4 ms |
16732 KB |
Output is correct |
18 |
Correct |
4 ms |
16732 KB |
Output is correct |
19 |
Correct |
4 ms |
16732 KB |
Output is correct |
20 |
Correct |
4 ms |
16732 KB |
Output is correct |
21 |
Correct |
4 ms |
16728 KB |
Output is correct |
22 |
Correct |
4 ms |
16732 KB |
Output is correct |
23 |
Correct |
5 ms |
16844 KB |
Output is correct |
24 |
Correct |
4 ms |
16732 KB |
Output is correct |
25 |
Correct |
4 ms |
16732 KB |
Output is correct |
26 |
Correct |
4 ms |
16884 KB |
Output is correct |
27 |
Correct |
4 ms |
16732 KB |
Output is correct |
28 |
Correct |
4 ms |
16732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
16732 KB |
Output is correct |
2 |
Correct |
4 ms |
16732 KB |
Output is correct |
3 |
Correct |
4 ms |
16728 KB |
Output is correct |
4 |
Correct |
4 ms |
16840 KB |
Output is correct |
5 |
Correct |
4 ms |
16732 KB |
Output is correct |
6 |
Correct |
4 ms |
16732 KB |
Output is correct |
7 |
Correct |
4 ms |
16828 KB |
Output is correct |
8 |
Correct |
4 ms |
16732 KB |
Output is correct |
9 |
Correct |
4 ms |
16732 KB |
Output is correct |
10 |
Correct |
5 ms |
16732 KB |
Output is correct |
11 |
Correct |
6 ms |
16732 KB |
Output is correct |
12 |
Correct |
4 ms |
16732 KB |
Output is correct |
13 |
Correct |
5 ms |
16732 KB |
Output is correct |
14 |
Correct |
4 ms |
16732 KB |
Output is correct |
15 |
Correct |
4 ms |
16732 KB |
Output is correct |
16 |
Correct |
4 ms |
16732 KB |
Output is correct |
17 |
Correct |
4 ms |
16732 KB |
Output is correct |
18 |
Correct |
4 ms |
16732 KB |
Output is correct |
19 |
Correct |
4 ms |
16732 KB |
Output is correct |
20 |
Correct |
4 ms |
16732 KB |
Output is correct |
21 |
Correct |
4 ms |
16728 KB |
Output is correct |
22 |
Correct |
4 ms |
16732 KB |
Output is correct |
23 |
Correct |
5 ms |
16844 KB |
Output is correct |
24 |
Correct |
4 ms |
16732 KB |
Output is correct |
25 |
Correct |
4 ms |
16732 KB |
Output is correct |
26 |
Correct |
4 ms |
16884 KB |
Output is correct |
27 |
Correct |
4 ms |
16732 KB |
Output is correct |
28 |
Correct |
4 ms |
16732 KB |
Output is correct |
29 |
Correct |
22 ms |
17044 KB |
Output is correct |
30 |
Correct |
37 ms |
17228 KB |
Output is correct |
31 |
Correct |
37 ms |
17240 KB |
Output is correct |
32 |
Correct |
26 ms |
16988 KB |
Output is correct |
33 |
Correct |
19 ms |
16988 KB |
Output is correct |
34 |
Correct |
40 ms |
17244 KB |
Output is correct |
35 |
Correct |
42 ms |
17244 KB |
Output is correct |
36 |
Correct |
28 ms |
17244 KB |
Output is correct |
37 |
Correct |
47 ms |
19320 KB |
Output is correct |
38 |
Correct |
51 ms |
18268 KB |
Output is correct |
39 |
Correct |
37 ms |
17508 KB |
Output is correct |
40 |
Correct |
29 ms |
17144 KB |
Output is correct |
41 |
Correct |
27 ms |
17240 KB |
Output is correct |
42 |
Correct |
26 ms |
16988 KB |
Output is correct |
43 |
Correct |
22 ms |
16988 KB |
Output is correct |
44 |
Correct |
29 ms |
16988 KB |
Output is correct |
45 |
Correct |
40 ms |
17244 KB |
Output is correct |
46 |
Correct |
46 ms |
17496 KB |
Output is correct |
47 |
Correct |
24 ms |
16988 KB |
Output is correct |
48 |
Correct |
26 ms |
16984 KB |
Output is correct |
49 |
Correct |
35 ms |
17540 KB |
Output is correct |
50 |
Correct |
42 ms |
17240 KB |
Output is correct |
51 |
Correct |
22 ms |
16984 KB |
Output is correct |
52 |
Correct |
26 ms |
16984 KB |
Output is correct |
53 |
Correct |
37 ms |
17108 KB |
Output is correct |
54 |
Correct |
42 ms |
17244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
16732 KB |
Output is correct |
2 |
Correct |
4 ms |
16732 KB |
Output is correct |
3 |
Correct |
106 ms |
28644 KB |
Output is correct |
4 |
Correct |
140 ms |
35316 KB |
Output is correct |
5 |
Correct |
134 ms |
33988 KB |
Output is correct |
6 |
Correct |
123 ms |
29540 KB |
Output is correct |
7 |
Correct |
138 ms |
30448 KB |
Output is correct |
8 |
Correct |
113 ms |
27328 KB |
Output is correct |
9 |
Correct |
114 ms |
29576 KB |
Output is correct |
10 |
Correct |
144 ms |
35560 KB |
Output is correct |
11 |
Correct |
136 ms |
29508 KB |
Output is correct |
12 |
Correct |
137 ms |
33756 KB |
Output is correct |
13 |
Correct |
97 ms |
25024 KB |
Output is correct |
14 |
Correct |
112 ms |
27072 KB |
Output is correct |
15 |
Correct |
131 ms |
31684 KB |
Output is correct |
16 |
Correct |
150 ms |
35384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
16732 KB |
Output is correct |
2 |
Correct |
4 ms |
16732 KB |
Output is correct |
3 |
Correct |
4 ms |
16728 KB |
Output is correct |
4 |
Correct |
4 ms |
16840 KB |
Output is correct |
5 |
Correct |
4 ms |
16732 KB |
Output is correct |
6 |
Correct |
4 ms |
16732 KB |
Output is correct |
7 |
Correct |
4 ms |
16828 KB |
Output is correct |
8 |
Correct |
4 ms |
16732 KB |
Output is correct |
9 |
Correct |
4 ms |
16732 KB |
Output is correct |
10 |
Correct |
5 ms |
16732 KB |
Output is correct |
11 |
Correct |
6 ms |
16732 KB |
Output is correct |
12 |
Correct |
4 ms |
16732 KB |
Output is correct |
13 |
Correct |
5 ms |
16732 KB |
Output is correct |
14 |
Correct |
4 ms |
16732 KB |
Output is correct |
15 |
Correct |
4 ms |
16732 KB |
Output is correct |
16 |
Correct |
4 ms |
16732 KB |
Output is correct |
17 |
Correct |
4 ms |
16732 KB |
Output is correct |
18 |
Correct |
4 ms |
16732 KB |
Output is correct |
19 |
Correct |
4 ms |
16732 KB |
Output is correct |
20 |
Correct |
4 ms |
16732 KB |
Output is correct |
21 |
Correct |
4 ms |
16728 KB |
Output is correct |
22 |
Correct |
4 ms |
16732 KB |
Output is correct |
23 |
Correct |
5 ms |
16844 KB |
Output is correct |
24 |
Correct |
4 ms |
16732 KB |
Output is correct |
25 |
Correct |
4 ms |
16732 KB |
Output is correct |
26 |
Correct |
4 ms |
16884 KB |
Output is correct |
27 |
Correct |
4 ms |
16732 KB |
Output is correct |
28 |
Correct |
4 ms |
16732 KB |
Output is correct |
29 |
Correct |
106 ms |
28644 KB |
Output is correct |
30 |
Correct |
140 ms |
35316 KB |
Output is correct |
31 |
Correct |
134 ms |
33988 KB |
Output is correct |
32 |
Correct |
123 ms |
29540 KB |
Output is correct |
33 |
Correct |
138 ms |
30448 KB |
Output is correct |
34 |
Correct |
113 ms |
27328 KB |
Output is correct |
35 |
Correct |
114 ms |
29576 KB |
Output is correct |
36 |
Correct |
144 ms |
35560 KB |
Output is correct |
37 |
Correct |
136 ms |
29508 KB |
Output is correct |
38 |
Correct |
137 ms |
33756 KB |
Output is correct |
39 |
Correct |
97 ms |
25024 KB |
Output is correct |
40 |
Correct |
112 ms |
27072 KB |
Output is correct |
41 |
Correct |
131 ms |
31684 KB |
Output is correct |
42 |
Correct |
150 ms |
35384 KB |
Output is correct |
43 |
Correct |
1562 ms |
192668 KB |
Output is correct |
44 |
Execution timed out |
2050 ms |
218816 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
16732 KB |
Output is correct |
2 |
Correct |
4 ms |
16732 KB |
Output is correct |
3 |
Correct |
4 ms |
16728 KB |
Output is correct |
4 |
Correct |
4 ms |
16840 KB |
Output is correct |
5 |
Correct |
4 ms |
16732 KB |
Output is correct |
6 |
Correct |
4 ms |
16732 KB |
Output is correct |
7 |
Correct |
4 ms |
16828 KB |
Output is correct |
8 |
Correct |
4 ms |
16732 KB |
Output is correct |
9 |
Correct |
4 ms |
16732 KB |
Output is correct |
10 |
Correct |
5 ms |
16732 KB |
Output is correct |
11 |
Correct |
6 ms |
16732 KB |
Output is correct |
12 |
Correct |
4 ms |
16732 KB |
Output is correct |
13 |
Correct |
5 ms |
16732 KB |
Output is correct |
14 |
Correct |
4 ms |
16732 KB |
Output is correct |
15 |
Correct |
4 ms |
16732 KB |
Output is correct |
16 |
Correct |
4 ms |
16732 KB |
Output is correct |
17 |
Correct |
4 ms |
16732 KB |
Output is correct |
18 |
Correct |
4 ms |
16732 KB |
Output is correct |
19 |
Correct |
4 ms |
16732 KB |
Output is correct |
20 |
Correct |
4 ms |
16732 KB |
Output is correct |
21 |
Correct |
4 ms |
16728 KB |
Output is correct |
22 |
Correct |
4 ms |
16732 KB |
Output is correct |
23 |
Correct |
5 ms |
16844 KB |
Output is correct |
24 |
Correct |
4 ms |
16732 KB |
Output is correct |
25 |
Correct |
4 ms |
16732 KB |
Output is correct |
26 |
Correct |
4 ms |
16884 KB |
Output is correct |
27 |
Correct |
4 ms |
16732 KB |
Output is correct |
28 |
Correct |
4 ms |
16732 KB |
Output is correct |
29 |
Correct |
22 ms |
17044 KB |
Output is correct |
30 |
Correct |
37 ms |
17228 KB |
Output is correct |
31 |
Correct |
37 ms |
17240 KB |
Output is correct |
32 |
Correct |
26 ms |
16988 KB |
Output is correct |
33 |
Correct |
19 ms |
16988 KB |
Output is correct |
34 |
Correct |
40 ms |
17244 KB |
Output is correct |
35 |
Correct |
42 ms |
17244 KB |
Output is correct |
36 |
Correct |
28 ms |
17244 KB |
Output is correct |
37 |
Correct |
47 ms |
19320 KB |
Output is correct |
38 |
Correct |
51 ms |
18268 KB |
Output is correct |
39 |
Correct |
37 ms |
17508 KB |
Output is correct |
40 |
Correct |
29 ms |
17144 KB |
Output is correct |
41 |
Correct |
27 ms |
17240 KB |
Output is correct |
42 |
Correct |
26 ms |
16988 KB |
Output is correct |
43 |
Correct |
22 ms |
16988 KB |
Output is correct |
44 |
Correct |
29 ms |
16988 KB |
Output is correct |
45 |
Correct |
40 ms |
17244 KB |
Output is correct |
46 |
Correct |
46 ms |
17496 KB |
Output is correct |
47 |
Correct |
24 ms |
16988 KB |
Output is correct |
48 |
Correct |
26 ms |
16984 KB |
Output is correct |
49 |
Correct |
35 ms |
17540 KB |
Output is correct |
50 |
Correct |
42 ms |
17240 KB |
Output is correct |
51 |
Correct |
22 ms |
16984 KB |
Output is correct |
52 |
Correct |
26 ms |
16984 KB |
Output is correct |
53 |
Correct |
37 ms |
17108 KB |
Output is correct |
54 |
Correct |
42 ms |
17244 KB |
Output is correct |
55 |
Execution timed out |
2045 ms |
177616 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
16732 KB |
Output is correct |
2 |
Correct |
4 ms |
16732 KB |
Output is correct |
3 |
Correct |
4 ms |
16728 KB |
Output is correct |
4 |
Correct |
4 ms |
16840 KB |
Output is correct |
5 |
Correct |
4 ms |
16732 KB |
Output is correct |
6 |
Correct |
4 ms |
16732 KB |
Output is correct |
7 |
Correct |
4 ms |
16828 KB |
Output is correct |
8 |
Correct |
4 ms |
16732 KB |
Output is correct |
9 |
Correct |
4 ms |
16732 KB |
Output is correct |
10 |
Correct |
5 ms |
16732 KB |
Output is correct |
11 |
Correct |
6 ms |
16732 KB |
Output is correct |
12 |
Correct |
4 ms |
16732 KB |
Output is correct |
13 |
Correct |
5 ms |
16732 KB |
Output is correct |
14 |
Correct |
4 ms |
16732 KB |
Output is correct |
15 |
Correct |
4 ms |
16732 KB |
Output is correct |
16 |
Correct |
4 ms |
16732 KB |
Output is correct |
17 |
Correct |
4 ms |
16732 KB |
Output is correct |
18 |
Correct |
4 ms |
16732 KB |
Output is correct |
19 |
Correct |
4 ms |
16732 KB |
Output is correct |
20 |
Correct |
4 ms |
16732 KB |
Output is correct |
21 |
Correct |
4 ms |
16728 KB |
Output is correct |
22 |
Correct |
4 ms |
16732 KB |
Output is correct |
23 |
Correct |
5 ms |
16844 KB |
Output is correct |
24 |
Correct |
4 ms |
16732 KB |
Output is correct |
25 |
Correct |
4 ms |
16732 KB |
Output is correct |
26 |
Correct |
4 ms |
16884 KB |
Output is correct |
27 |
Correct |
4 ms |
16732 KB |
Output is correct |
28 |
Correct |
4 ms |
16732 KB |
Output is correct |
29 |
Correct |
22 ms |
17044 KB |
Output is correct |
30 |
Correct |
37 ms |
17228 KB |
Output is correct |
31 |
Correct |
37 ms |
17240 KB |
Output is correct |
32 |
Correct |
26 ms |
16988 KB |
Output is correct |
33 |
Correct |
19 ms |
16988 KB |
Output is correct |
34 |
Correct |
40 ms |
17244 KB |
Output is correct |
35 |
Correct |
42 ms |
17244 KB |
Output is correct |
36 |
Correct |
28 ms |
17244 KB |
Output is correct |
37 |
Correct |
47 ms |
19320 KB |
Output is correct |
38 |
Correct |
51 ms |
18268 KB |
Output is correct |
39 |
Correct |
37 ms |
17508 KB |
Output is correct |
40 |
Correct |
29 ms |
17144 KB |
Output is correct |
41 |
Correct |
27 ms |
17240 KB |
Output is correct |
42 |
Correct |
26 ms |
16988 KB |
Output is correct |
43 |
Correct |
22 ms |
16988 KB |
Output is correct |
44 |
Correct |
29 ms |
16988 KB |
Output is correct |
45 |
Correct |
40 ms |
17244 KB |
Output is correct |
46 |
Correct |
46 ms |
17496 KB |
Output is correct |
47 |
Correct |
24 ms |
16988 KB |
Output is correct |
48 |
Correct |
26 ms |
16984 KB |
Output is correct |
49 |
Correct |
35 ms |
17540 KB |
Output is correct |
50 |
Correct |
42 ms |
17240 KB |
Output is correct |
51 |
Correct |
22 ms |
16984 KB |
Output is correct |
52 |
Correct |
26 ms |
16984 KB |
Output is correct |
53 |
Correct |
37 ms |
17108 KB |
Output is correct |
54 |
Correct |
42 ms |
17244 KB |
Output is correct |
55 |
Correct |
106 ms |
28644 KB |
Output is correct |
56 |
Correct |
140 ms |
35316 KB |
Output is correct |
57 |
Correct |
134 ms |
33988 KB |
Output is correct |
58 |
Correct |
123 ms |
29540 KB |
Output is correct |
59 |
Correct |
138 ms |
30448 KB |
Output is correct |
60 |
Correct |
113 ms |
27328 KB |
Output is correct |
61 |
Correct |
114 ms |
29576 KB |
Output is correct |
62 |
Correct |
144 ms |
35560 KB |
Output is correct |
63 |
Correct |
136 ms |
29508 KB |
Output is correct |
64 |
Correct |
137 ms |
33756 KB |
Output is correct |
65 |
Correct |
97 ms |
25024 KB |
Output is correct |
66 |
Correct |
112 ms |
27072 KB |
Output is correct |
67 |
Correct |
131 ms |
31684 KB |
Output is correct |
68 |
Correct |
150 ms |
35384 KB |
Output is correct |
69 |
Correct |
1562 ms |
192668 KB |
Output is correct |
70 |
Execution timed out |
2050 ms |
218816 KB |
Time limit exceeded |
71 |
Halted |
0 ms |
0 KB |
- |