#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define fastIO cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false);
#define mid ((l + r) / 2)
#define lChild ((index * 2) + 1)
#define rChild ((index * 2) + 2)
using namespace std;
struct node {
ll u, i;
};
bool bi(vector<vector<node> >& graph, vector<ll>& color, ll startIndex, ll p, ll col, ll l, ll r) {
color[startIndex] = col;
ll ret = true;
for(auto [el, i] : graph[startIndex]) {
if(el == p || (l <= i && i <= r)) continue;
if(color[el] == -1) ret &= bi(graph, color, el, startIndex, !col, l, r);
if(color[el] != -1 && color[el] == col) return false;
if(color[el] != col) continue;
}
return ret;
}
bool check(vector<vector<node> >& graph, ll i, ll l = 0) {
ll n = graph.size();
vector<ll> col(n, -1);
ll ans = true;
for(int j = 0; j < n; j++) {
if(col[j] != -1) continue;
ans &= bi(graph, col, j, -1, 0, l, i);
}
return !ans;
}
void solve(ll _) {
ll n, m, q; cin>>n>>m>>q;
vector<vector<node> > graph(n);
for(int i = 0; i < m; i++) {
ll x, y; cin>>x>>y;
x--; y--;
graph[x].push_back({y, i});
graph[y].push_back({x, i});
}
ll l = 0, r = m - 1;
while(l < r) {
bool ckB = check(graph, mid - 1), ck = check(graph, mid), ckA = check(graph, mid + 1);
/* if(mid - 1 < 0) {
l = r = 0;
break;
}
if(mid + 1 >= m) {
l = r = m - 1;
break;
}*/
if(ckB != ckA) {
l = r = mid;
break;
}
//cout<<mid<<": => "<<ck<<endl;
if(!ck) {
r = mid - 1;
} else {
l = mid + 1;
}
}
bool is = check(graph, l);
ll x = l;
// cout<<" => "<<l<<" "<<r<<endl;
for(int i = 0; i < q; i++) {
ll l, r; cin>>l>>r;
l--; r--;
//l = 0, r = min(q - 1, (ll)i);
if(n <= 2050 && q <= 2050) {
cout<<(check(graph, r, l) ? "YES" : "NO")<<endl;
continue;
}
if( x < r) cout<<"NO"<<endl;
else if(r < x) cout<<"YES"<<endl;
else {
cout<<(is ? "YES" : "NO")<<endl;
}
}
}
int main() {
//fastIO
//freopen("file.in", "r", stdin);
//freopen("file.out", "w", stdout);
ll t = 0; solve(t);
}
Compilation message
Joker.cpp: In function 'bool bi(std::vector<std::vector<node> >&, std::vector<long long int>&, long long int, long long int, long long int, long long int, long long int)':
Joker.cpp:22:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
22 | for(auto [el, i] : graph[startIndex]) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
544 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
544 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
45 ms |
344 KB |
Output is correct |
30 |
Correct |
102 ms |
624 KB |
Output is correct |
31 |
Correct |
100 ms |
604 KB |
Output is correct |
32 |
Correct |
87 ms |
604 KB |
Output is correct |
33 |
Correct |
46 ms |
620 KB |
Output is correct |
34 |
Correct |
111 ms |
604 KB |
Output is correct |
35 |
Correct |
112 ms |
600 KB |
Output is correct |
36 |
Correct |
30 ms |
600 KB |
Output is correct |
37 |
Correct |
66 ms |
604 KB |
Output is correct |
38 |
Correct |
49 ms |
604 KB |
Output is correct |
39 |
Correct |
70 ms |
604 KB |
Output is correct |
40 |
Correct |
63 ms |
604 KB |
Output is correct |
41 |
Correct |
63 ms |
604 KB |
Output is correct |
42 |
Correct |
64 ms |
600 KB |
Output is correct |
43 |
Correct |
43 ms |
600 KB |
Output is correct |
44 |
Correct |
69 ms |
604 KB |
Output is correct |
45 |
Correct |
84 ms |
664 KB |
Output is correct |
46 |
Correct |
86 ms |
604 KB |
Output is correct |
47 |
Correct |
58 ms |
600 KB |
Output is correct |
48 |
Correct |
72 ms |
604 KB |
Output is correct |
49 |
Correct |
91 ms |
604 KB |
Output is correct |
50 |
Correct |
101 ms |
852 KB |
Output is correct |
51 |
Correct |
56 ms |
600 KB |
Output is correct |
52 |
Correct |
71 ms |
624 KB |
Output is correct |
53 |
Correct |
88 ms |
652 KB |
Output is correct |
54 |
Correct |
123 ms |
644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1145 ms |
20464 KB |
Output is correct |
4 |
Correct |
1696 ms |
24932 KB |
Output is correct |
5 |
Correct |
1186 ms |
23172 KB |
Output is correct |
6 |
Correct |
491 ms |
20616 KB |
Output is correct |
7 |
Correct |
438 ms |
18664 KB |
Output is correct |
8 |
Correct |
451 ms |
20640 KB |
Output is correct |
9 |
Correct |
455 ms |
21184 KB |
Output is correct |
10 |
Correct |
1618 ms |
24100 KB |
Output is correct |
11 |
Correct |
833 ms |
21868 KB |
Output is correct |
12 |
Correct |
1118 ms |
22832 KB |
Output is correct |
13 |
Correct |
461 ms |
18032 KB |
Output is correct |
14 |
Correct |
445 ms |
21160 KB |
Output is correct |
15 |
Correct |
1123 ms |
24492 KB |
Output is correct |
16 |
Correct |
1543 ms |
24712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
544 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1145 ms |
20464 KB |
Output is correct |
30 |
Correct |
1696 ms |
24932 KB |
Output is correct |
31 |
Correct |
1186 ms |
23172 KB |
Output is correct |
32 |
Correct |
491 ms |
20616 KB |
Output is correct |
33 |
Correct |
438 ms |
18664 KB |
Output is correct |
34 |
Correct |
451 ms |
20640 KB |
Output is correct |
35 |
Correct |
455 ms |
21184 KB |
Output is correct |
36 |
Correct |
1618 ms |
24100 KB |
Output is correct |
37 |
Correct |
833 ms |
21868 KB |
Output is correct |
38 |
Correct |
1118 ms |
22832 KB |
Output is correct |
39 |
Correct |
461 ms |
18032 KB |
Output is correct |
40 |
Correct |
445 ms |
21160 KB |
Output is correct |
41 |
Correct |
1123 ms |
24492 KB |
Output is correct |
42 |
Correct |
1543 ms |
24712 KB |
Output is correct |
43 |
Incorrect |
1022 ms |
24224 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
544 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
45 ms |
344 KB |
Output is correct |
30 |
Correct |
102 ms |
624 KB |
Output is correct |
31 |
Correct |
100 ms |
604 KB |
Output is correct |
32 |
Correct |
87 ms |
604 KB |
Output is correct |
33 |
Correct |
46 ms |
620 KB |
Output is correct |
34 |
Correct |
111 ms |
604 KB |
Output is correct |
35 |
Correct |
112 ms |
600 KB |
Output is correct |
36 |
Correct |
30 ms |
600 KB |
Output is correct |
37 |
Correct |
66 ms |
604 KB |
Output is correct |
38 |
Correct |
49 ms |
604 KB |
Output is correct |
39 |
Correct |
70 ms |
604 KB |
Output is correct |
40 |
Correct |
63 ms |
604 KB |
Output is correct |
41 |
Correct |
63 ms |
604 KB |
Output is correct |
42 |
Correct |
64 ms |
600 KB |
Output is correct |
43 |
Correct |
43 ms |
600 KB |
Output is correct |
44 |
Correct |
69 ms |
604 KB |
Output is correct |
45 |
Correct |
84 ms |
664 KB |
Output is correct |
46 |
Correct |
86 ms |
604 KB |
Output is correct |
47 |
Correct |
58 ms |
600 KB |
Output is correct |
48 |
Correct |
72 ms |
604 KB |
Output is correct |
49 |
Correct |
91 ms |
604 KB |
Output is correct |
50 |
Correct |
101 ms |
852 KB |
Output is correct |
51 |
Correct |
56 ms |
600 KB |
Output is correct |
52 |
Correct |
71 ms |
624 KB |
Output is correct |
53 |
Correct |
88 ms |
652 KB |
Output is correct |
54 |
Correct |
123 ms |
644 KB |
Output is correct |
55 |
Incorrect |
692 ms |
23460 KB |
Output isn't correct |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
544 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
45 ms |
344 KB |
Output is correct |
30 |
Correct |
102 ms |
624 KB |
Output is correct |
31 |
Correct |
100 ms |
604 KB |
Output is correct |
32 |
Correct |
87 ms |
604 KB |
Output is correct |
33 |
Correct |
46 ms |
620 KB |
Output is correct |
34 |
Correct |
111 ms |
604 KB |
Output is correct |
35 |
Correct |
112 ms |
600 KB |
Output is correct |
36 |
Correct |
30 ms |
600 KB |
Output is correct |
37 |
Correct |
66 ms |
604 KB |
Output is correct |
38 |
Correct |
49 ms |
604 KB |
Output is correct |
39 |
Correct |
70 ms |
604 KB |
Output is correct |
40 |
Correct |
63 ms |
604 KB |
Output is correct |
41 |
Correct |
63 ms |
604 KB |
Output is correct |
42 |
Correct |
64 ms |
600 KB |
Output is correct |
43 |
Correct |
43 ms |
600 KB |
Output is correct |
44 |
Correct |
69 ms |
604 KB |
Output is correct |
45 |
Correct |
84 ms |
664 KB |
Output is correct |
46 |
Correct |
86 ms |
604 KB |
Output is correct |
47 |
Correct |
58 ms |
600 KB |
Output is correct |
48 |
Correct |
72 ms |
604 KB |
Output is correct |
49 |
Correct |
91 ms |
604 KB |
Output is correct |
50 |
Correct |
101 ms |
852 KB |
Output is correct |
51 |
Correct |
56 ms |
600 KB |
Output is correct |
52 |
Correct |
71 ms |
624 KB |
Output is correct |
53 |
Correct |
88 ms |
652 KB |
Output is correct |
54 |
Correct |
123 ms |
644 KB |
Output is correct |
55 |
Correct |
1145 ms |
20464 KB |
Output is correct |
56 |
Correct |
1696 ms |
24932 KB |
Output is correct |
57 |
Correct |
1186 ms |
23172 KB |
Output is correct |
58 |
Correct |
491 ms |
20616 KB |
Output is correct |
59 |
Correct |
438 ms |
18664 KB |
Output is correct |
60 |
Correct |
451 ms |
20640 KB |
Output is correct |
61 |
Correct |
455 ms |
21184 KB |
Output is correct |
62 |
Correct |
1618 ms |
24100 KB |
Output is correct |
63 |
Correct |
833 ms |
21868 KB |
Output is correct |
64 |
Correct |
1118 ms |
22832 KB |
Output is correct |
65 |
Correct |
461 ms |
18032 KB |
Output is correct |
66 |
Correct |
445 ms |
21160 KB |
Output is correct |
67 |
Correct |
1123 ms |
24492 KB |
Output is correct |
68 |
Correct |
1543 ms |
24712 KB |
Output is correct |
69 |
Incorrect |
1022 ms |
24224 KB |
Output isn't correct |
70 |
Halted |
0 ms |
0 KB |
- |