#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 2e5;
vector<pair<int, int> > g[N+1];
int n, m, q, timer = 1;
int used[N+1], lens[N+1];
int Left, Right, ok;
vector< pair<int, int> > query;
void dfs(int v, int par){
if(ok) return;
used[v] = timer;
for(auto [to, idx] : g[v]){
if(used[to] == timer && (idx < Left or idx > Right) && to != par){
int len = lens[v] - lens[to] + 1;
if(len % 2 == 1){
ok = 1;
return;
}
}else if(used[to] < timer && (idx < Left or idx > Right)){
lens[to] = lens[v] + 1;
dfs(to, v);
}
}
used[v] = timer+1;
}
main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m >> q;
for(int i = 0;i < m; i++){
int a, b; cin >> a >> b;
g[a].push_back({b, i + 1});
g[b].push_back({a, i + 1});
}
int subtask = 1;
query.resize(q);
for(int i = 0;i < q; i++){
cin >> query[i].ff >> query[i].ss;
if(query[i].ff != 1) subtask = 0;
}
if(subtask && max({n, m, q}) > 2000){
int l = 0, r = m + 1;
while(l + 1 < r){
int mid = (l + r) >> 1;
Left = 1, Right = mid, ok = 0;
for(int i = 1;i <= n; i++){
if(used[i] < timer){
lens[i] = 1;
dfs(i, -1);
if(ok) break;
}
}
timer+= 2;
if(ok) l =mid;
else r = mid;
}
for(int j = 0;j < q; j++){
if(query[j].ss <= l){
cout << "YES";
}else cout << "NO";
cout << '\n';
}
return 0;
}
for(int j = 0;j < q; j++){
Left = query[j].ff, Right = query[j].ss;
ok = 0;
for(int i = 1;i <= n; i++){
if(used[i] < timer){
lens[i] = 1;
dfs(i, -1);
if(ok) break;
}
}
timer+= 2;
cout << (ok ? "YES" : "NO") << '\n';
}
return 0;
}
Compilation message
Joker.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
36 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6492 KB |
Output is correct |
12 |
Correct |
2 ms |
6488 KB |
Output is correct |
13 |
Correct |
2 ms |
6316 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
3 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6492 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6744 KB |
Output is correct |
23 |
Correct |
2 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6544 KB |
Output is correct |
25 |
Correct |
2 ms |
6396 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
2 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6492 KB |
Output is correct |
12 |
Correct |
2 ms |
6488 KB |
Output is correct |
13 |
Correct |
2 ms |
6316 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
3 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6492 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6744 KB |
Output is correct |
23 |
Correct |
2 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6544 KB |
Output is correct |
25 |
Correct |
2 ms |
6396 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
2 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
61 ms |
6492 KB |
Output is correct |
30 |
Correct |
49 ms |
6660 KB |
Output is correct |
31 |
Correct |
39 ms |
6488 KB |
Output is correct |
32 |
Correct |
23 ms |
6680 KB |
Output is correct |
33 |
Correct |
13 ms |
6668 KB |
Output is correct |
34 |
Correct |
35 ms |
6492 KB |
Output is correct |
35 |
Correct |
55 ms |
6488 KB |
Output is correct |
36 |
Correct |
17 ms |
6488 KB |
Output is correct |
37 |
Correct |
60 ms |
6492 KB |
Output is correct |
38 |
Correct |
51 ms |
6492 KB |
Output is correct |
39 |
Correct |
50 ms |
6748 KB |
Output is correct |
40 |
Correct |
31 ms |
6492 KB |
Output is correct |
41 |
Correct |
29 ms |
6492 KB |
Output is correct |
42 |
Correct |
29 ms |
6492 KB |
Output is correct |
43 |
Correct |
11 ms |
6744 KB |
Output is correct |
44 |
Correct |
8 ms |
6492 KB |
Output is correct |
45 |
Correct |
10 ms |
6672 KB |
Output is correct |
46 |
Correct |
13 ms |
6492 KB |
Output is correct |
47 |
Correct |
29 ms |
6684 KB |
Output is correct |
48 |
Correct |
30 ms |
6492 KB |
Output is correct |
49 |
Correct |
37 ms |
6488 KB |
Output is correct |
50 |
Correct |
42 ms |
6492 KB |
Output is correct |
51 |
Correct |
31 ms |
6488 KB |
Output is correct |
52 |
Correct |
33 ms |
6492 KB |
Output is correct |
53 |
Correct |
41 ms |
6492 KB |
Output is correct |
54 |
Correct |
51 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
107 ms |
18768 KB |
Output is correct |
4 |
Correct |
233 ms |
20564 KB |
Output is correct |
5 |
Correct |
118 ms |
20436 KB |
Output is correct |
6 |
Correct |
115 ms |
20564 KB |
Output is correct |
7 |
Correct |
99 ms |
19228 KB |
Output is correct |
8 |
Correct |
80 ms |
20564 KB |
Output is correct |
9 |
Correct |
92 ms |
20564 KB |
Output is correct |
10 |
Correct |
171 ms |
19700 KB |
Output is correct |
11 |
Correct |
95 ms |
18892 KB |
Output is correct |
12 |
Correct |
142 ms |
19576 KB |
Output is correct |
13 |
Correct |
73 ms |
19280 KB |
Output is correct |
14 |
Correct |
81 ms |
21048 KB |
Output is correct |
15 |
Correct |
122 ms |
20524 KB |
Output is correct |
16 |
Correct |
175 ms |
20092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6492 KB |
Output is correct |
12 |
Correct |
2 ms |
6488 KB |
Output is correct |
13 |
Correct |
2 ms |
6316 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
3 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6492 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6744 KB |
Output is correct |
23 |
Correct |
2 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6544 KB |
Output is correct |
25 |
Correct |
2 ms |
6396 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
2 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
107 ms |
18768 KB |
Output is correct |
30 |
Correct |
233 ms |
20564 KB |
Output is correct |
31 |
Correct |
118 ms |
20436 KB |
Output is correct |
32 |
Correct |
115 ms |
20564 KB |
Output is correct |
33 |
Correct |
99 ms |
19228 KB |
Output is correct |
34 |
Correct |
80 ms |
20564 KB |
Output is correct |
35 |
Correct |
92 ms |
20564 KB |
Output is correct |
36 |
Correct |
171 ms |
19700 KB |
Output is correct |
37 |
Correct |
95 ms |
18892 KB |
Output is correct |
38 |
Correct |
142 ms |
19576 KB |
Output is correct |
39 |
Correct |
73 ms |
19280 KB |
Output is correct |
40 |
Correct |
81 ms |
21048 KB |
Output is correct |
41 |
Correct |
122 ms |
20524 KB |
Output is correct |
42 |
Correct |
175 ms |
20092 KB |
Output is correct |
43 |
Execution timed out |
2092 ms |
24144 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6492 KB |
Output is correct |
12 |
Correct |
2 ms |
6488 KB |
Output is correct |
13 |
Correct |
2 ms |
6316 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
3 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6492 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6744 KB |
Output is correct |
23 |
Correct |
2 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6544 KB |
Output is correct |
25 |
Correct |
2 ms |
6396 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
2 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
61 ms |
6492 KB |
Output is correct |
30 |
Correct |
49 ms |
6660 KB |
Output is correct |
31 |
Correct |
39 ms |
6488 KB |
Output is correct |
32 |
Correct |
23 ms |
6680 KB |
Output is correct |
33 |
Correct |
13 ms |
6668 KB |
Output is correct |
34 |
Correct |
35 ms |
6492 KB |
Output is correct |
35 |
Correct |
55 ms |
6488 KB |
Output is correct |
36 |
Correct |
17 ms |
6488 KB |
Output is correct |
37 |
Correct |
60 ms |
6492 KB |
Output is correct |
38 |
Correct |
51 ms |
6492 KB |
Output is correct |
39 |
Correct |
50 ms |
6748 KB |
Output is correct |
40 |
Correct |
31 ms |
6492 KB |
Output is correct |
41 |
Correct |
29 ms |
6492 KB |
Output is correct |
42 |
Correct |
29 ms |
6492 KB |
Output is correct |
43 |
Correct |
11 ms |
6744 KB |
Output is correct |
44 |
Correct |
8 ms |
6492 KB |
Output is correct |
45 |
Correct |
10 ms |
6672 KB |
Output is correct |
46 |
Correct |
13 ms |
6492 KB |
Output is correct |
47 |
Correct |
29 ms |
6684 KB |
Output is correct |
48 |
Correct |
30 ms |
6492 KB |
Output is correct |
49 |
Correct |
37 ms |
6488 KB |
Output is correct |
50 |
Correct |
42 ms |
6492 KB |
Output is correct |
51 |
Correct |
31 ms |
6488 KB |
Output is correct |
52 |
Correct |
33 ms |
6492 KB |
Output is correct |
53 |
Correct |
41 ms |
6492 KB |
Output is correct |
54 |
Correct |
51 ms |
6492 KB |
Output is correct |
55 |
Execution timed out |
2040 ms |
20432 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6492 KB |
Output is correct |
12 |
Correct |
2 ms |
6488 KB |
Output is correct |
13 |
Correct |
2 ms |
6316 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
3 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6492 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6744 KB |
Output is correct |
23 |
Correct |
2 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6544 KB |
Output is correct |
25 |
Correct |
2 ms |
6396 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
2 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
61 ms |
6492 KB |
Output is correct |
30 |
Correct |
49 ms |
6660 KB |
Output is correct |
31 |
Correct |
39 ms |
6488 KB |
Output is correct |
32 |
Correct |
23 ms |
6680 KB |
Output is correct |
33 |
Correct |
13 ms |
6668 KB |
Output is correct |
34 |
Correct |
35 ms |
6492 KB |
Output is correct |
35 |
Correct |
55 ms |
6488 KB |
Output is correct |
36 |
Correct |
17 ms |
6488 KB |
Output is correct |
37 |
Correct |
60 ms |
6492 KB |
Output is correct |
38 |
Correct |
51 ms |
6492 KB |
Output is correct |
39 |
Correct |
50 ms |
6748 KB |
Output is correct |
40 |
Correct |
31 ms |
6492 KB |
Output is correct |
41 |
Correct |
29 ms |
6492 KB |
Output is correct |
42 |
Correct |
29 ms |
6492 KB |
Output is correct |
43 |
Correct |
11 ms |
6744 KB |
Output is correct |
44 |
Correct |
8 ms |
6492 KB |
Output is correct |
45 |
Correct |
10 ms |
6672 KB |
Output is correct |
46 |
Correct |
13 ms |
6492 KB |
Output is correct |
47 |
Correct |
29 ms |
6684 KB |
Output is correct |
48 |
Correct |
30 ms |
6492 KB |
Output is correct |
49 |
Correct |
37 ms |
6488 KB |
Output is correct |
50 |
Correct |
42 ms |
6492 KB |
Output is correct |
51 |
Correct |
31 ms |
6488 KB |
Output is correct |
52 |
Correct |
33 ms |
6492 KB |
Output is correct |
53 |
Correct |
41 ms |
6492 KB |
Output is correct |
54 |
Correct |
51 ms |
6492 KB |
Output is correct |
55 |
Correct |
107 ms |
18768 KB |
Output is correct |
56 |
Correct |
233 ms |
20564 KB |
Output is correct |
57 |
Correct |
118 ms |
20436 KB |
Output is correct |
58 |
Correct |
115 ms |
20564 KB |
Output is correct |
59 |
Correct |
99 ms |
19228 KB |
Output is correct |
60 |
Correct |
80 ms |
20564 KB |
Output is correct |
61 |
Correct |
92 ms |
20564 KB |
Output is correct |
62 |
Correct |
171 ms |
19700 KB |
Output is correct |
63 |
Correct |
95 ms |
18892 KB |
Output is correct |
64 |
Correct |
142 ms |
19576 KB |
Output is correct |
65 |
Correct |
73 ms |
19280 KB |
Output is correct |
66 |
Correct |
81 ms |
21048 KB |
Output is correct |
67 |
Correct |
122 ms |
20524 KB |
Output is correct |
68 |
Correct |
175 ms |
20092 KB |
Output is correct |
69 |
Execution timed out |
2092 ms |
24144 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |