#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[2005];
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 <= m; 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 |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
4 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12636 KB |
Output is correct |
8 |
Correct |
4 ms |
12632 KB |
Output is correct |
9 |
Correct |
3 ms |
12636 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
3 ms |
12636 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
4 ms |
12740 KB |
Output is correct |
16 |
Correct |
3 ms |
12780 KB |
Output is correct |
17 |
Correct |
3 ms |
12636 KB |
Output is correct |
18 |
Correct |
4 ms |
12636 KB |
Output is correct |
19 |
Correct |
3 ms |
12636 KB |
Output is correct |
20 |
Correct |
3 ms |
12636 KB |
Output is correct |
21 |
Correct |
3 ms |
12636 KB |
Output is correct |
22 |
Correct |
3 ms |
12636 KB |
Output is correct |
23 |
Correct |
3 ms |
12636 KB |
Output is correct |
24 |
Correct |
3 ms |
12636 KB |
Output is correct |
25 |
Correct |
3 ms |
12636 KB |
Output is correct |
26 |
Correct |
4 ms |
12636 KB |
Output is correct |
27 |
Correct |
3 ms |
12636 KB |
Output is correct |
28 |
Correct |
4 ms |
12632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
4 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12636 KB |
Output is correct |
8 |
Correct |
4 ms |
12632 KB |
Output is correct |
9 |
Correct |
3 ms |
12636 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
3 ms |
12636 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
4 ms |
12740 KB |
Output is correct |
16 |
Correct |
3 ms |
12780 KB |
Output is correct |
17 |
Correct |
3 ms |
12636 KB |
Output is correct |
18 |
Correct |
4 ms |
12636 KB |
Output is correct |
19 |
Correct |
3 ms |
12636 KB |
Output is correct |
20 |
Correct |
3 ms |
12636 KB |
Output is correct |
21 |
Correct |
3 ms |
12636 KB |
Output is correct |
22 |
Correct |
3 ms |
12636 KB |
Output is correct |
23 |
Correct |
3 ms |
12636 KB |
Output is correct |
24 |
Correct |
3 ms |
12636 KB |
Output is correct |
25 |
Correct |
3 ms |
12636 KB |
Output is correct |
26 |
Correct |
4 ms |
12636 KB |
Output is correct |
27 |
Correct |
3 ms |
12636 KB |
Output is correct |
28 |
Correct |
4 ms |
12632 KB |
Output is correct |
29 |
Correct |
21 ms |
12892 KB |
Output is correct |
30 |
Correct |
35 ms |
13148 KB |
Output is correct |
31 |
Correct |
35 ms |
13144 KB |
Output is correct |
32 |
Correct |
26 ms |
13024 KB |
Output is correct |
33 |
Correct |
19 ms |
12888 KB |
Output is correct |
34 |
Correct |
39 ms |
13148 KB |
Output is correct |
35 |
Correct |
41 ms |
13148 KB |
Output is correct |
36 |
Correct |
27 ms |
13148 KB |
Output is correct |
37 |
Correct |
51 ms |
15096 KB |
Output is correct |
38 |
Correct |
48 ms |
14172 KB |
Output is correct |
39 |
Correct |
36 ms |
13148 KB |
Output is correct |
40 |
Correct |
27 ms |
12888 KB |
Output is correct |
41 |
Correct |
31 ms |
12892 KB |
Output is correct |
42 |
Correct |
27 ms |
12892 KB |
Output is correct |
43 |
Correct |
22 ms |
12980 KB |
Output is correct |
44 |
Correct |
28 ms |
12888 KB |
Output is correct |
45 |
Correct |
41 ms |
13144 KB |
Output is correct |
46 |
Correct |
46 ms |
13148 KB |
Output is correct |
47 |
Correct |
23 ms |
12892 KB |
Output is correct |
48 |
Correct |
30 ms |
13148 KB |
Output is correct |
49 |
Correct |
31 ms |
13148 KB |
Output is correct |
50 |
Correct |
40 ms |
13148 KB |
Output is correct |
51 |
Correct |
21 ms |
13000 KB |
Output is correct |
52 |
Correct |
25 ms |
12892 KB |
Output is correct |
53 |
Correct |
31 ms |
13160 KB |
Output is correct |
54 |
Correct |
40 ms |
13144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Runtime error |
101 ms |
38460 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
4 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12636 KB |
Output is correct |
8 |
Correct |
4 ms |
12632 KB |
Output is correct |
9 |
Correct |
3 ms |
12636 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
3 ms |
12636 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
4 ms |
12740 KB |
Output is correct |
16 |
Correct |
3 ms |
12780 KB |
Output is correct |
17 |
Correct |
3 ms |
12636 KB |
Output is correct |
18 |
Correct |
4 ms |
12636 KB |
Output is correct |
19 |
Correct |
3 ms |
12636 KB |
Output is correct |
20 |
Correct |
3 ms |
12636 KB |
Output is correct |
21 |
Correct |
3 ms |
12636 KB |
Output is correct |
22 |
Correct |
3 ms |
12636 KB |
Output is correct |
23 |
Correct |
3 ms |
12636 KB |
Output is correct |
24 |
Correct |
3 ms |
12636 KB |
Output is correct |
25 |
Correct |
3 ms |
12636 KB |
Output is correct |
26 |
Correct |
4 ms |
12636 KB |
Output is correct |
27 |
Correct |
3 ms |
12636 KB |
Output is correct |
28 |
Correct |
4 ms |
12632 KB |
Output is correct |
29 |
Runtime error |
101 ms |
38460 KB |
Execution killed with signal 11 |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
4 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12636 KB |
Output is correct |
8 |
Correct |
4 ms |
12632 KB |
Output is correct |
9 |
Correct |
3 ms |
12636 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
3 ms |
12636 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
4 ms |
12740 KB |
Output is correct |
16 |
Correct |
3 ms |
12780 KB |
Output is correct |
17 |
Correct |
3 ms |
12636 KB |
Output is correct |
18 |
Correct |
4 ms |
12636 KB |
Output is correct |
19 |
Correct |
3 ms |
12636 KB |
Output is correct |
20 |
Correct |
3 ms |
12636 KB |
Output is correct |
21 |
Correct |
3 ms |
12636 KB |
Output is correct |
22 |
Correct |
3 ms |
12636 KB |
Output is correct |
23 |
Correct |
3 ms |
12636 KB |
Output is correct |
24 |
Correct |
3 ms |
12636 KB |
Output is correct |
25 |
Correct |
3 ms |
12636 KB |
Output is correct |
26 |
Correct |
4 ms |
12636 KB |
Output is correct |
27 |
Correct |
3 ms |
12636 KB |
Output is correct |
28 |
Correct |
4 ms |
12632 KB |
Output is correct |
29 |
Correct |
21 ms |
12892 KB |
Output is correct |
30 |
Correct |
35 ms |
13148 KB |
Output is correct |
31 |
Correct |
35 ms |
13144 KB |
Output is correct |
32 |
Correct |
26 ms |
13024 KB |
Output is correct |
33 |
Correct |
19 ms |
12888 KB |
Output is correct |
34 |
Correct |
39 ms |
13148 KB |
Output is correct |
35 |
Correct |
41 ms |
13148 KB |
Output is correct |
36 |
Correct |
27 ms |
13148 KB |
Output is correct |
37 |
Correct |
51 ms |
15096 KB |
Output is correct |
38 |
Correct |
48 ms |
14172 KB |
Output is correct |
39 |
Correct |
36 ms |
13148 KB |
Output is correct |
40 |
Correct |
27 ms |
12888 KB |
Output is correct |
41 |
Correct |
31 ms |
12892 KB |
Output is correct |
42 |
Correct |
27 ms |
12892 KB |
Output is correct |
43 |
Correct |
22 ms |
12980 KB |
Output is correct |
44 |
Correct |
28 ms |
12888 KB |
Output is correct |
45 |
Correct |
41 ms |
13144 KB |
Output is correct |
46 |
Correct |
46 ms |
13148 KB |
Output is correct |
47 |
Correct |
23 ms |
12892 KB |
Output is correct |
48 |
Correct |
30 ms |
13148 KB |
Output is correct |
49 |
Correct |
31 ms |
13148 KB |
Output is correct |
50 |
Correct |
40 ms |
13148 KB |
Output is correct |
51 |
Correct |
21 ms |
13000 KB |
Output is correct |
52 |
Correct |
25 ms |
12892 KB |
Output is correct |
53 |
Correct |
31 ms |
13160 KB |
Output is correct |
54 |
Correct |
40 ms |
13144 KB |
Output is correct |
55 |
Runtime error |
67 ms |
34896 KB |
Execution killed with signal 11 |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
4 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12636 KB |
Output is correct |
8 |
Correct |
4 ms |
12632 KB |
Output is correct |
9 |
Correct |
3 ms |
12636 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
3 ms |
12636 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
4 ms |
12740 KB |
Output is correct |
16 |
Correct |
3 ms |
12780 KB |
Output is correct |
17 |
Correct |
3 ms |
12636 KB |
Output is correct |
18 |
Correct |
4 ms |
12636 KB |
Output is correct |
19 |
Correct |
3 ms |
12636 KB |
Output is correct |
20 |
Correct |
3 ms |
12636 KB |
Output is correct |
21 |
Correct |
3 ms |
12636 KB |
Output is correct |
22 |
Correct |
3 ms |
12636 KB |
Output is correct |
23 |
Correct |
3 ms |
12636 KB |
Output is correct |
24 |
Correct |
3 ms |
12636 KB |
Output is correct |
25 |
Correct |
3 ms |
12636 KB |
Output is correct |
26 |
Correct |
4 ms |
12636 KB |
Output is correct |
27 |
Correct |
3 ms |
12636 KB |
Output is correct |
28 |
Correct |
4 ms |
12632 KB |
Output is correct |
29 |
Correct |
21 ms |
12892 KB |
Output is correct |
30 |
Correct |
35 ms |
13148 KB |
Output is correct |
31 |
Correct |
35 ms |
13144 KB |
Output is correct |
32 |
Correct |
26 ms |
13024 KB |
Output is correct |
33 |
Correct |
19 ms |
12888 KB |
Output is correct |
34 |
Correct |
39 ms |
13148 KB |
Output is correct |
35 |
Correct |
41 ms |
13148 KB |
Output is correct |
36 |
Correct |
27 ms |
13148 KB |
Output is correct |
37 |
Correct |
51 ms |
15096 KB |
Output is correct |
38 |
Correct |
48 ms |
14172 KB |
Output is correct |
39 |
Correct |
36 ms |
13148 KB |
Output is correct |
40 |
Correct |
27 ms |
12888 KB |
Output is correct |
41 |
Correct |
31 ms |
12892 KB |
Output is correct |
42 |
Correct |
27 ms |
12892 KB |
Output is correct |
43 |
Correct |
22 ms |
12980 KB |
Output is correct |
44 |
Correct |
28 ms |
12888 KB |
Output is correct |
45 |
Correct |
41 ms |
13144 KB |
Output is correct |
46 |
Correct |
46 ms |
13148 KB |
Output is correct |
47 |
Correct |
23 ms |
12892 KB |
Output is correct |
48 |
Correct |
30 ms |
13148 KB |
Output is correct |
49 |
Correct |
31 ms |
13148 KB |
Output is correct |
50 |
Correct |
40 ms |
13148 KB |
Output is correct |
51 |
Correct |
21 ms |
13000 KB |
Output is correct |
52 |
Correct |
25 ms |
12892 KB |
Output is correct |
53 |
Correct |
31 ms |
13160 KB |
Output is correct |
54 |
Correct |
40 ms |
13144 KB |
Output is correct |
55 |
Runtime error |
101 ms |
38460 KB |
Execution killed with signal 11 |
56 |
Halted |
0 ms |
0 KB |
- |