#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "../Library/debug.h"
#else
#define dbg(x...)
// #define cin fin
// #define cout fout
// const string FILE_NAME = ""; ifstream fin(FILE_NAME + ".in"); ofstream fout(FILE_NAME + ".out");
#endif
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; --i)
#define trav(a, x) for (auto& a : x)
#define f first
#define s second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
const char nl = '\n';
const int INF = 1e9;
const int MOD = 1e9 + 7;
vector<vi> adj;
vi edges, good;
vi color;
bool cycle = false;
void dfs(int u, int p, int c){
if(color[u] != -1 && color[u] != c){
cycle = true;
return;
}
if(color[u] != -1)
return;
color[u] = c;
trav(id, adj[u]){
if(!good[id]) continue;
int v = edges[id] ^ u;
if(v == p)
continue;
dfs(v, u, c ^ 1);
}
}
void solve(){
int n, m, q;
cin >> n >> m >> q;
adj.resize(n);
edges.resize(m);
F0R(i, m){
int a, b;
cin >> a >> b;
--a, --b;
edges[i] = a ^ b;
adj[a].pb(i);
adj[b].pb(i);
}
if(max({n, m, q}) <= 2000){
color.resize(n);
good.resize(m);
while(q--){
int a, b;
cin >> a >> b;
a--, b--;
color = vector<int>(n, -1);
F0R(i, m){
if(i >= a && i <= b)
good[i] = false;
else good[i] = true;
}
cycle = false;
F0R(i, n){
if(color[i] == -1)
dfs(i, -1, 1);
}
if(cycle)
cout << "YES\n";
else cout << "NO\n";
dbg(color)
}
return;
}
color.resize(n);
good.resize(m);
auto f = [&](int a, int b){
color = vector<int>(n, -1);
F0R(i, m){
if(i >= a && i <= b)
good[i] = false;
else good[i] = true;
}
cycle = false;
F0R(i, n){
if(color[i] == -1)
dfs(i, -1, 1);
}
return cycle;
};
vector<array<int, 3>> queries(q);
F0R(i, q){
cin >> queries[i][0] >> queries[i][1];
queries[i][0]--, queries[i][1]--;
queries[i][2] = i;
}
sort(all(queries), [&](array<int, 3>& a, array<int, 3>& b) {return a[1] < b[1];});
int l = 0, r = q - 1, point = -1;
while(l <= r){
int m = (l + r) / 2;
if(f(queries[m][0], queries[m][1])){
point = m;
l = m + 1;
}
else{
r = m - 1;
}
}
if(point == -1){
F0R(i, q){
cout << "NO\n";
}
}
else{
F0R(i, point + 1)
queries[i][0] = 1;
FOR(i, point + 1, q)
queries[i][0] = 0;
sort(all(queries), [&](array<int, 3>& a, array<int, 3>& b){return a[2] < b[2];});
F0R(i, q){
if(queries[i][0] == 1)
cout << "YES\n";
else cout << "NO\n";
}
}
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int TC = 1;
// cin >> TC;
while(TC--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 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 |
0 ms |
348 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 |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 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 |
0 ms |
348 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 |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
30 ms |
348 KB |
Output is correct |
30 |
Correct |
75 ms |
608 KB |
Output is correct |
31 |
Correct |
91 ms |
348 KB |
Output is correct |
32 |
Correct |
82 ms |
344 KB |
Output is correct |
33 |
Correct |
61 ms |
536 KB |
Output is correct |
34 |
Correct |
79 ms |
604 KB |
Output is correct |
35 |
Correct |
84 ms |
604 KB |
Output is correct |
36 |
Correct |
26 ms |
604 KB |
Output is correct |
37 |
Correct |
40 ms |
632 KB |
Output is correct |
38 |
Correct |
38 ms |
604 KB |
Output is correct |
39 |
Correct |
50 ms |
616 KB |
Output is correct |
40 |
Correct |
60 ms |
564 KB |
Output is correct |
41 |
Correct |
60 ms |
344 KB |
Output is correct |
42 |
Correct |
58 ms |
584 KB |
Output is correct |
43 |
Correct |
49 ms |
536 KB |
Output is correct |
44 |
Correct |
59 ms |
348 KB |
Output is correct |
45 |
Correct |
63 ms |
604 KB |
Output is correct |
46 |
Correct |
66 ms |
600 KB |
Output is correct |
47 |
Correct |
56 ms |
348 KB |
Output is correct |
48 |
Correct |
60 ms |
344 KB |
Output is correct |
49 |
Correct |
65 ms |
348 KB |
Output is correct |
50 |
Correct |
67 ms |
584 KB |
Output is correct |
51 |
Correct |
61 ms |
348 KB |
Output is correct |
52 |
Correct |
73 ms |
348 KB |
Output is correct |
53 |
Correct |
75 ms |
344 KB |
Output is correct |
54 |
Correct |
82 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
105 ms |
15428 KB |
Output is correct |
4 |
Correct |
133 ms |
19688 KB |
Output is correct |
5 |
Correct |
141 ms |
16332 KB |
Output is correct |
6 |
Correct |
154 ms |
13948 KB |
Output is correct |
7 |
Correct |
156 ms |
13888 KB |
Output is correct |
8 |
Correct |
179 ms |
13176 KB |
Output is correct |
9 |
Correct |
197 ms |
15944 KB |
Output is correct |
10 |
Correct |
231 ms |
20172 KB |
Output is correct |
11 |
Correct |
162 ms |
13124 KB |
Output is correct |
12 |
Correct |
178 ms |
15952 KB |
Output is correct |
13 |
Correct |
117 ms |
9548 KB |
Output is correct |
14 |
Correct |
175 ms |
12524 KB |
Output is correct |
15 |
Correct |
203 ms |
15344 KB |
Output is correct |
16 |
Correct |
220 ms |
16940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 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 |
0 ms |
348 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 |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
105 ms |
15428 KB |
Output is correct |
30 |
Correct |
133 ms |
19688 KB |
Output is correct |
31 |
Correct |
141 ms |
16332 KB |
Output is correct |
32 |
Correct |
154 ms |
13948 KB |
Output is correct |
33 |
Correct |
156 ms |
13888 KB |
Output is correct |
34 |
Correct |
179 ms |
13176 KB |
Output is correct |
35 |
Correct |
197 ms |
15944 KB |
Output is correct |
36 |
Correct |
231 ms |
20172 KB |
Output is correct |
37 |
Correct |
162 ms |
13124 KB |
Output is correct |
38 |
Correct |
178 ms |
15952 KB |
Output is correct |
39 |
Correct |
117 ms |
9548 KB |
Output is correct |
40 |
Correct |
175 ms |
12524 KB |
Output is correct |
41 |
Correct |
203 ms |
15344 KB |
Output is correct |
42 |
Correct |
220 ms |
16940 KB |
Output is correct |
43 |
Incorrect |
114 ms |
21832 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 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 |
0 ms |
348 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 |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
30 ms |
348 KB |
Output is correct |
30 |
Correct |
75 ms |
608 KB |
Output is correct |
31 |
Correct |
91 ms |
348 KB |
Output is correct |
32 |
Correct |
82 ms |
344 KB |
Output is correct |
33 |
Correct |
61 ms |
536 KB |
Output is correct |
34 |
Correct |
79 ms |
604 KB |
Output is correct |
35 |
Correct |
84 ms |
604 KB |
Output is correct |
36 |
Correct |
26 ms |
604 KB |
Output is correct |
37 |
Correct |
40 ms |
632 KB |
Output is correct |
38 |
Correct |
38 ms |
604 KB |
Output is correct |
39 |
Correct |
50 ms |
616 KB |
Output is correct |
40 |
Correct |
60 ms |
564 KB |
Output is correct |
41 |
Correct |
60 ms |
344 KB |
Output is correct |
42 |
Correct |
58 ms |
584 KB |
Output is correct |
43 |
Correct |
49 ms |
536 KB |
Output is correct |
44 |
Correct |
59 ms |
348 KB |
Output is correct |
45 |
Correct |
63 ms |
604 KB |
Output is correct |
46 |
Correct |
66 ms |
600 KB |
Output is correct |
47 |
Correct |
56 ms |
348 KB |
Output is correct |
48 |
Correct |
60 ms |
344 KB |
Output is correct |
49 |
Correct |
65 ms |
348 KB |
Output is correct |
50 |
Correct |
67 ms |
584 KB |
Output is correct |
51 |
Correct |
61 ms |
348 KB |
Output is correct |
52 |
Correct |
73 ms |
348 KB |
Output is correct |
53 |
Correct |
75 ms |
344 KB |
Output is correct |
54 |
Correct |
82 ms |
604 KB |
Output is correct |
55 |
Incorrect |
60 ms |
14032 KB |
Output isn't correct |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 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 |
0 ms |
348 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 |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
30 ms |
348 KB |
Output is correct |
30 |
Correct |
75 ms |
608 KB |
Output is correct |
31 |
Correct |
91 ms |
348 KB |
Output is correct |
32 |
Correct |
82 ms |
344 KB |
Output is correct |
33 |
Correct |
61 ms |
536 KB |
Output is correct |
34 |
Correct |
79 ms |
604 KB |
Output is correct |
35 |
Correct |
84 ms |
604 KB |
Output is correct |
36 |
Correct |
26 ms |
604 KB |
Output is correct |
37 |
Correct |
40 ms |
632 KB |
Output is correct |
38 |
Correct |
38 ms |
604 KB |
Output is correct |
39 |
Correct |
50 ms |
616 KB |
Output is correct |
40 |
Correct |
60 ms |
564 KB |
Output is correct |
41 |
Correct |
60 ms |
344 KB |
Output is correct |
42 |
Correct |
58 ms |
584 KB |
Output is correct |
43 |
Correct |
49 ms |
536 KB |
Output is correct |
44 |
Correct |
59 ms |
348 KB |
Output is correct |
45 |
Correct |
63 ms |
604 KB |
Output is correct |
46 |
Correct |
66 ms |
600 KB |
Output is correct |
47 |
Correct |
56 ms |
348 KB |
Output is correct |
48 |
Correct |
60 ms |
344 KB |
Output is correct |
49 |
Correct |
65 ms |
348 KB |
Output is correct |
50 |
Correct |
67 ms |
584 KB |
Output is correct |
51 |
Correct |
61 ms |
348 KB |
Output is correct |
52 |
Correct |
73 ms |
348 KB |
Output is correct |
53 |
Correct |
75 ms |
344 KB |
Output is correct |
54 |
Correct |
82 ms |
604 KB |
Output is correct |
55 |
Correct |
105 ms |
15428 KB |
Output is correct |
56 |
Correct |
133 ms |
19688 KB |
Output is correct |
57 |
Correct |
141 ms |
16332 KB |
Output is correct |
58 |
Correct |
154 ms |
13948 KB |
Output is correct |
59 |
Correct |
156 ms |
13888 KB |
Output is correct |
60 |
Correct |
179 ms |
13176 KB |
Output is correct |
61 |
Correct |
197 ms |
15944 KB |
Output is correct |
62 |
Correct |
231 ms |
20172 KB |
Output is correct |
63 |
Correct |
162 ms |
13124 KB |
Output is correct |
64 |
Correct |
178 ms |
15952 KB |
Output is correct |
65 |
Correct |
117 ms |
9548 KB |
Output is correct |
66 |
Correct |
175 ms |
12524 KB |
Output is correct |
67 |
Correct |
203 ms |
15344 KB |
Output is correct |
68 |
Correct |
220 ms |
16940 KB |
Output is correct |
69 |
Incorrect |
114 ms |
21832 KB |
Output isn't correct |
70 |
Halted |
0 ms |
0 KB |
- |