#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//#define int long long
#define pb push_back
#define mp make_pair
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
constexpr int N = (int)2e5 + 111;
constexpr int md = (int)2e5 + 111;
mt19937 rnd(time(nullptr));
vector<int> g[N];
bool used[2][N];
bool c[2][N];
bool dfs(int v,int r,int pr = -1){
used[r][v] = true;
c[r][v] = true;
for(auto& to : g[v]){
if(pr == to)
continue;
if(used[r^1][to]){
if(c[r][v]&c[r][to])
return true;
continue;
}
c[r^1][to] = true;
if(dfs(to,r^1,v))
return true;
}
return false;
}
int n,m,q;
vector<pair<int,int>> edges;
bool can(int l,int r){
for(int j = 0; j <= n; j++){
used[0][j] = false;
used[1][j] = false;
c[0][j] = c[1][j] = 0;
g[j].clear();
}
bool have = false;
for(int j = 0; j < l-1; j++){
auto&[a,b] = edges[j];
g[a].pb(b);
g[b].pb(a);
}
for(int j = r; j < m; j++){
auto&[a,b] = edges[j];
g[a].pb(b);
g[b].pb(a);
}
for(int j = 1; j <= n; j++){
if(!used[0][j] && !used[1][j]){
c[0][j] = 1;
if(dfs(j,0)){
return true;
}
}
}
return false;
}
void solve(){
cin >> n >> m >> q;
for(int i = 0; i < m; i++){
int a,b;
cin >> a >> b;
edges.pb(mp(a,b));
}
bool answer[q];
bool f = true;
if(!can(1,0))
f = false;
vector<pair<int,int>> Queries[m+1];
for(int i = 0; i < q; i++){
int l,r;
cin >> l >> r;
if(!f){
cout << "NO\n";
continue;
}
Queries[l].pb(mp(r,i));
}
if(!f)
return;
for(int i = 0; i <= m; i++){
if(Queries[i].empty())
continue;
sort(Queries[i].rbegin(),Queries[i].rend());
if(!can(i,i)){
for(auto&[r,id] : Queries[i]){
answer[id] = 0;
}
continue;
}
int L = i, R = m;
while(R - L > 1){
int mid = (L+R)>>1;
if(can(i,mid))
L = mid;
else
R = mid;
}
while(!can(i,R))R--;
for(auto&[r,id] : Queries[i]){
if(r <= R && f)
answer[id] = 1;
else
answer[id] = 0;
}
}
for(int i = 0; i < q; i++){
cout << (answer[i] ? "YES" : "NO") << "\n";
}
return;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
// init();
int tests = 1;
// cin >> tests;
for(int test = 1; test <= tests; test++){
// cerr << "test = " << test << "\n";
solve();
}
return 0;
}
/**
6 8 2
1 3
1 5
1 6
2 5
2 6
3 4
3 5
5 6
4 7
4 8
**/
Compilation message
Joker.cpp: In function 'bool can(int, int)':
Joker.cpp:52:10: warning: unused variable 'have' [-Wunused-variable]
52 | bool have = false;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
7 ms |
4948 KB |
Output is correct |
9 |
Correct |
6 ms |
4948 KB |
Output is correct |
10 |
Correct |
5 ms |
4948 KB |
Output is correct |
11 |
Correct |
7 ms |
5068 KB |
Output is correct |
12 |
Correct |
7 ms |
4948 KB |
Output is correct |
13 |
Correct |
7 ms |
4948 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
8 ms |
4948 KB |
Output is correct |
16 |
Correct |
6 ms |
5064 KB |
Output is correct |
17 |
Correct |
5 ms |
4948 KB |
Output is correct |
18 |
Correct |
5 ms |
4948 KB |
Output is correct |
19 |
Correct |
6 ms |
5056 KB |
Output is correct |
20 |
Correct |
5 ms |
4948 KB |
Output is correct |
21 |
Correct |
5 ms |
4948 KB |
Output is correct |
22 |
Correct |
7 ms |
4960 KB |
Output is correct |
23 |
Correct |
6 ms |
4948 KB |
Output is correct |
24 |
Correct |
6 ms |
5040 KB |
Output is correct |
25 |
Correct |
6 ms |
5060 KB |
Output is correct |
26 |
Correct |
6 ms |
4948 KB |
Output is correct |
27 |
Correct |
6 ms |
4948 KB |
Output is correct |
28 |
Correct |
7 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
7 ms |
4948 KB |
Output is correct |
9 |
Correct |
6 ms |
4948 KB |
Output is correct |
10 |
Correct |
5 ms |
4948 KB |
Output is correct |
11 |
Correct |
7 ms |
5068 KB |
Output is correct |
12 |
Correct |
7 ms |
4948 KB |
Output is correct |
13 |
Correct |
7 ms |
4948 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
8 ms |
4948 KB |
Output is correct |
16 |
Correct |
6 ms |
5064 KB |
Output is correct |
17 |
Correct |
5 ms |
4948 KB |
Output is correct |
18 |
Correct |
5 ms |
4948 KB |
Output is correct |
19 |
Correct |
6 ms |
5056 KB |
Output is correct |
20 |
Correct |
5 ms |
4948 KB |
Output is correct |
21 |
Correct |
5 ms |
4948 KB |
Output is correct |
22 |
Correct |
7 ms |
4960 KB |
Output is correct |
23 |
Correct |
6 ms |
4948 KB |
Output is correct |
24 |
Correct |
6 ms |
5040 KB |
Output is correct |
25 |
Correct |
6 ms |
5060 KB |
Output is correct |
26 |
Correct |
6 ms |
4948 KB |
Output is correct |
27 |
Correct |
6 ms |
4948 KB |
Output is correct |
28 |
Correct |
7 ms |
4948 KB |
Output is correct |
29 |
Correct |
3 ms |
5076 KB |
Output is correct |
30 |
Correct |
463 ms |
5204 KB |
Output is correct |
31 |
Correct |
455 ms |
5212 KB |
Output is correct |
32 |
Correct |
346 ms |
5204 KB |
Output is correct |
33 |
Correct |
282 ms |
5076 KB |
Output is correct |
34 |
Correct |
466 ms |
5224 KB |
Output is correct |
35 |
Correct |
544 ms |
5220 KB |
Output is correct |
36 |
Correct |
426 ms |
5332 KB |
Output is correct |
37 |
Correct |
655 ms |
5204 KB |
Output is correct |
38 |
Correct |
4 ms |
5076 KB |
Output is correct |
39 |
Correct |
424 ms |
5228 KB |
Output is correct |
40 |
Correct |
338 ms |
5208 KB |
Output is correct |
41 |
Correct |
334 ms |
5328 KB |
Output is correct |
42 |
Correct |
330 ms |
5204 KB |
Output is correct |
43 |
Correct |
287 ms |
5204 KB |
Output is correct |
44 |
Correct |
365 ms |
5200 KB |
Output is correct |
45 |
Correct |
433 ms |
5208 KB |
Output is correct |
46 |
Correct |
527 ms |
5216 KB |
Output is correct |
47 |
Correct |
342 ms |
5196 KB |
Output is correct |
48 |
Correct |
355 ms |
5188 KB |
Output is correct |
49 |
Correct |
371 ms |
5204 KB |
Output is correct |
50 |
Correct |
438 ms |
5204 KB |
Output is correct |
51 |
Correct |
319 ms |
5324 KB |
Output is correct |
52 |
Correct |
357 ms |
5204 KB |
Output is correct |
53 |
Correct |
421 ms |
5324 KB |
Output is correct |
54 |
Correct |
478 ms |
5228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
295 ms |
26088 KB |
Output is correct |
4 |
Correct |
125 ms |
19200 KB |
Output is correct |
5 |
Correct |
314 ms |
22308 KB |
Output is correct |
6 |
Correct |
437 ms |
20196 KB |
Output is correct |
7 |
Correct |
409 ms |
19140 KB |
Output is correct |
8 |
Correct |
263 ms |
20592 KB |
Output is correct |
9 |
Correct |
412 ms |
20996 KB |
Output is correct |
10 |
Correct |
810 ms |
20836 KB |
Output is correct |
11 |
Correct |
296 ms |
19040 KB |
Output is correct |
12 |
Correct |
407 ms |
20476 KB |
Output is correct |
13 |
Correct |
179 ms |
18312 KB |
Output is correct |
14 |
Correct |
276 ms |
20520 KB |
Output is correct |
15 |
Correct |
359 ms |
20200 KB |
Output is correct |
16 |
Correct |
447 ms |
20848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
7 ms |
4948 KB |
Output is correct |
9 |
Correct |
6 ms |
4948 KB |
Output is correct |
10 |
Correct |
5 ms |
4948 KB |
Output is correct |
11 |
Correct |
7 ms |
5068 KB |
Output is correct |
12 |
Correct |
7 ms |
4948 KB |
Output is correct |
13 |
Correct |
7 ms |
4948 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
8 ms |
4948 KB |
Output is correct |
16 |
Correct |
6 ms |
5064 KB |
Output is correct |
17 |
Correct |
5 ms |
4948 KB |
Output is correct |
18 |
Correct |
5 ms |
4948 KB |
Output is correct |
19 |
Correct |
6 ms |
5056 KB |
Output is correct |
20 |
Correct |
5 ms |
4948 KB |
Output is correct |
21 |
Correct |
5 ms |
4948 KB |
Output is correct |
22 |
Correct |
7 ms |
4960 KB |
Output is correct |
23 |
Correct |
6 ms |
4948 KB |
Output is correct |
24 |
Correct |
6 ms |
5040 KB |
Output is correct |
25 |
Correct |
6 ms |
5060 KB |
Output is correct |
26 |
Correct |
6 ms |
4948 KB |
Output is correct |
27 |
Correct |
6 ms |
4948 KB |
Output is correct |
28 |
Correct |
7 ms |
4948 KB |
Output is correct |
29 |
Correct |
295 ms |
26088 KB |
Output is correct |
30 |
Correct |
125 ms |
19200 KB |
Output is correct |
31 |
Correct |
314 ms |
22308 KB |
Output is correct |
32 |
Correct |
437 ms |
20196 KB |
Output is correct |
33 |
Correct |
409 ms |
19140 KB |
Output is correct |
34 |
Correct |
263 ms |
20592 KB |
Output is correct |
35 |
Correct |
412 ms |
20996 KB |
Output is correct |
36 |
Correct |
810 ms |
20836 KB |
Output is correct |
37 |
Correct |
296 ms |
19040 KB |
Output is correct |
38 |
Correct |
407 ms |
20476 KB |
Output is correct |
39 |
Correct |
179 ms |
18312 KB |
Output is correct |
40 |
Correct |
276 ms |
20520 KB |
Output is correct |
41 |
Correct |
359 ms |
20200 KB |
Output is correct |
42 |
Correct |
447 ms |
20848 KB |
Output is correct |
43 |
Execution timed out |
2090 ms |
36164 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
7 ms |
4948 KB |
Output is correct |
9 |
Correct |
6 ms |
4948 KB |
Output is correct |
10 |
Correct |
5 ms |
4948 KB |
Output is correct |
11 |
Correct |
7 ms |
5068 KB |
Output is correct |
12 |
Correct |
7 ms |
4948 KB |
Output is correct |
13 |
Correct |
7 ms |
4948 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
8 ms |
4948 KB |
Output is correct |
16 |
Correct |
6 ms |
5064 KB |
Output is correct |
17 |
Correct |
5 ms |
4948 KB |
Output is correct |
18 |
Correct |
5 ms |
4948 KB |
Output is correct |
19 |
Correct |
6 ms |
5056 KB |
Output is correct |
20 |
Correct |
5 ms |
4948 KB |
Output is correct |
21 |
Correct |
5 ms |
4948 KB |
Output is correct |
22 |
Correct |
7 ms |
4960 KB |
Output is correct |
23 |
Correct |
6 ms |
4948 KB |
Output is correct |
24 |
Correct |
6 ms |
5040 KB |
Output is correct |
25 |
Correct |
6 ms |
5060 KB |
Output is correct |
26 |
Correct |
6 ms |
4948 KB |
Output is correct |
27 |
Correct |
6 ms |
4948 KB |
Output is correct |
28 |
Correct |
7 ms |
4948 KB |
Output is correct |
29 |
Correct |
3 ms |
5076 KB |
Output is correct |
30 |
Correct |
463 ms |
5204 KB |
Output is correct |
31 |
Correct |
455 ms |
5212 KB |
Output is correct |
32 |
Correct |
346 ms |
5204 KB |
Output is correct |
33 |
Correct |
282 ms |
5076 KB |
Output is correct |
34 |
Correct |
466 ms |
5224 KB |
Output is correct |
35 |
Correct |
544 ms |
5220 KB |
Output is correct |
36 |
Correct |
426 ms |
5332 KB |
Output is correct |
37 |
Correct |
655 ms |
5204 KB |
Output is correct |
38 |
Correct |
4 ms |
5076 KB |
Output is correct |
39 |
Correct |
424 ms |
5228 KB |
Output is correct |
40 |
Correct |
338 ms |
5208 KB |
Output is correct |
41 |
Correct |
334 ms |
5328 KB |
Output is correct |
42 |
Correct |
330 ms |
5204 KB |
Output is correct |
43 |
Correct |
287 ms |
5204 KB |
Output is correct |
44 |
Correct |
365 ms |
5200 KB |
Output is correct |
45 |
Correct |
433 ms |
5208 KB |
Output is correct |
46 |
Correct |
527 ms |
5216 KB |
Output is correct |
47 |
Correct |
342 ms |
5196 KB |
Output is correct |
48 |
Correct |
355 ms |
5188 KB |
Output is correct |
49 |
Correct |
371 ms |
5204 KB |
Output is correct |
50 |
Correct |
438 ms |
5204 KB |
Output is correct |
51 |
Correct |
319 ms |
5324 KB |
Output is correct |
52 |
Correct |
357 ms |
5204 KB |
Output is correct |
53 |
Correct |
421 ms |
5324 KB |
Output is correct |
54 |
Correct |
478 ms |
5228 KB |
Output is correct |
55 |
Execution timed out |
2097 ms |
19864 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
7 ms |
4948 KB |
Output is correct |
9 |
Correct |
6 ms |
4948 KB |
Output is correct |
10 |
Correct |
5 ms |
4948 KB |
Output is correct |
11 |
Correct |
7 ms |
5068 KB |
Output is correct |
12 |
Correct |
7 ms |
4948 KB |
Output is correct |
13 |
Correct |
7 ms |
4948 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
8 ms |
4948 KB |
Output is correct |
16 |
Correct |
6 ms |
5064 KB |
Output is correct |
17 |
Correct |
5 ms |
4948 KB |
Output is correct |
18 |
Correct |
5 ms |
4948 KB |
Output is correct |
19 |
Correct |
6 ms |
5056 KB |
Output is correct |
20 |
Correct |
5 ms |
4948 KB |
Output is correct |
21 |
Correct |
5 ms |
4948 KB |
Output is correct |
22 |
Correct |
7 ms |
4960 KB |
Output is correct |
23 |
Correct |
6 ms |
4948 KB |
Output is correct |
24 |
Correct |
6 ms |
5040 KB |
Output is correct |
25 |
Correct |
6 ms |
5060 KB |
Output is correct |
26 |
Correct |
6 ms |
4948 KB |
Output is correct |
27 |
Correct |
6 ms |
4948 KB |
Output is correct |
28 |
Correct |
7 ms |
4948 KB |
Output is correct |
29 |
Correct |
3 ms |
5076 KB |
Output is correct |
30 |
Correct |
463 ms |
5204 KB |
Output is correct |
31 |
Correct |
455 ms |
5212 KB |
Output is correct |
32 |
Correct |
346 ms |
5204 KB |
Output is correct |
33 |
Correct |
282 ms |
5076 KB |
Output is correct |
34 |
Correct |
466 ms |
5224 KB |
Output is correct |
35 |
Correct |
544 ms |
5220 KB |
Output is correct |
36 |
Correct |
426 ms |
5332 KB |
Output is correct |
37 |
Correct |
655 ms |
5204 KB |
Output is correct |
38 |
Correct |
4 ms |
5076 KB |
Output is correct |
39 |
Correct |
424 ms |
5228 KB |
Output is correct |
40 |
Correct |
338 ms |
5208 KB |
Output is correct |
41 |
Correct |
334 ms |
5328 KB |
Output is correct |
42 |
Correct |
330 ms |
5204 KB |
Output is correct |
43 |
Correct |
287 ms |
5204 KB |
Output is correct |
44 |
Correct |
365 ms |
5200 KB |
Output is correct |
45 |
Correct |
433 ms |
5208 KB |
Output is correct |
46 |
Correct |
527 ms |
5216 KB |
Output is correct |
47 |
Correct |
342 ms |
5196 KB |
Output is correct |
48 |
Correct |
355 ms |
5188 KB |
Output is correct |
49 |
Correct |
371 ms |
5204 KB |
Output is correct |
50 |
Correct |
438 ms |
5204 KB |
Output is correct |
51 |
Correct |
319 ms |
5324 KB |
Output is correct |
52 |
Correct |
357 ms |
5204 KB |
Output is correct |
53 |
Correct |
421 ms |
5324 KB |
Output is correct |
54 |
Correct |
478 ms |
5228 KB |
Output is correct |
55 |
Correct |
295 ms |
26088 KB |
Output is correct |
56 |
Correct |
125 ms |
19200 KB |
Output is correct |
57 |
Correct |
314 ms |
22308 KB |
Output is correct |
58 |
Correct |
437 ms |
20196 KB |
Output is correct |
59 |
Correct |
409 ms |
19140 KB |
Output is correct |
60 |
Correct |
263 ms |
20592 KB |
Output is correct |
61 |
Correct |
412 ms |
20996 KB |
Output is correct |
62 |
Correct |
810 ms |
20836 KB |
Output is correct |
63 |
Correct |
296 ms |
19040 KB |
Output is correct |
64 |
Correct |
407 ms |
20476 KB |
Output is correct |
65 |
Correct |
179 ms |
18312 KB |
Output is correct |
66 |
Correct |
276 ms |
20520 KB |
Output is correct |
67 |
Correct |
359 ms |
20200 KB |
Output is correct |
68 |
Correct |
447 ms |
20848 KB |
Output is correct |
69 |
Execution timed out |
2090 ms |
36164 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |