#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5, MOD = 998244353;
int p[N],sz[N],n,m,q,d[N];
void reset(){
for(int i = 1;i <= n;i++){
sz[i] = 1;
p[i] = i;
d[i] = 0;
}
}
pair<int, int> get(int v) {
// cerr << v << ' ' << p[v] << '\n';
if(p[v] == v){
return {v,0};
}
pair<int,int> x = get(p[v]);
p[v] = x.first;
d[v] += x.second;
return {p[v],d[v]};
}
bool merge(int a,int b){
pair<int,int> x = get(a),y = get(b);
if(sz[x.first] < sz[y.first]){
swap(x,y);
}
a = x.first;
b = y.first;
if(a == b){
if(x.second % 2 == y.second % 2){
return false;
}
return true;
}
p[b] = a;
sz[a] += sz[b];
d[b] = (x.second % 2 == y.second % 2);
return true;
}
int x[N],y[N];
vector<pair<int,int>> qr[N];
vector<int> ids[N];
bool ans[N];
void test(){
cin >> n >> m >> q;
for(int i = 1;i <= m;i++){
cin >> x[i] >> y[i];
}
for(int i = 1;i <= q;i++){
int l,r;
cin >> l >> r;
qr[l].push_back({i,r});
}
for(int i = 1;i <= m;i++){
if(qr[i].size()){
reset();
}else continue;
for(int j = i;j <= m;j++){
ids[j].clear();
}
for(auto [id,j]:qr[i]){
ids[j].push_back(id);
}
bool is = true;
for(int j = 1;j < i;j++) {
is &= merge(x[j],y[j]);
}
for(int j = m;j >= i;j--){
for(int k:ids[j]){
ans[k] = (!is);
}
is &= merge(x[j],y[j]);
}
}
for(int i = 1;i <= q;i++){
cout << (ans[i] ? "YES\n":"NO\n");
}
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int T = 1;
// cin >> T;
while(T--){
test();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
3 ms |
12768 KB |
Output is correct |
4 |
Correct |
2 ms |
12632 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12632 KB |
Output is correct |
8 |
Correct |
3 ms |
12636 KB |
Output is correct |
9 |
Correct |
3 ms |
12636 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
4 ms |
12788 KB |
Output is correct |
12 |
Correct |
3 ms |
12632 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
3 ms |
12660 KB |
Output is correct |
17 |
Correct |
3 ms |
12632 KB |
Output is correct |
18 |
Correct |
3 ms |
12776 KB |
Output is correct |
19 |
Correct |
4 ms |
12636 KB |
Output is correct |
20 |
Correct |
3 ms |
12636 KB |
Output is correct |
21 |
Correct |
4 ms |
12632 KB |
Output is correct |
22 |
Correct |
3 ms |
12636 KB |
Output is correct |
23 |
Correct |
4 ms |
12636 KB |
Output is correct |
24 |
Correct |
4 ms |
12636 KB |
Output is correct |
25 |
Correct |
3 ms |
12636 KB |
Output is correct |
26 |
Correct |
3 ms |
12632 KB |
Output is correct |
27 |
Correct |
3 ms |
12636 KB |
Output is correct |
28 |
Correct |
3 ms |
12636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
3 ms |
12768 KB |
Output is correct |
4 |
Correct |
2 ms |
12632 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12632 KB |
Output is correct |
8 |
Correct |
3 ms |
12636 KB |
Output is correct |
9 |
Correct |
3 ms |
12636 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
4 ms |
12788 KB |
Output is correct |
12 |
Correct |
3 ms |
12632 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
3 ms |
12660 KB |
Output is correct |
17 |
Correct |
3 ms |
12632 KB |
Output is correct |
18 |
Correct |
3 ms |
12776 KB |
Output is correct |
19 |
Correct |
4 ms |
12636 KB |
Output is correct |
20 |
Correct |
3 ms |
12636 KB |
Output is correct |
21 |
Correct |
4 ms |
12632 KB |
Output is correct |
22 |
Correct |
3 ms |
12636 KB |
Output is correct |
23 |
Correct |
4 ms |
12636 KB |
Output is correct |
24 |
Correct |
4 ms |
12636 KB |
Output is correct |
25 |
Correct |
3 ms |
12636 KB |
Output is correct |
26 |
Correct |
3 ms |
12632 KB |
Output is correct |
27 |
Correct |
3 ms |
12636 KB |
Output is correct |
28 |
Correct |
3 ms |
12636 KB |
Output is correct |
29 |
Correct |
13 ms |
12636 KB |
Output is correct |
30 |
Correct |
35 ms |
12636 KB |
Output is correct |
31 |
Correct |
50 ms |
12636 KB |
Output is correct |
32 |
Correct |
39 ms |
12632 KB |
Output is correct |
33 |
Correct |
42 ms |
12852 KB |
Output is correct |
34 |
Correct |
41 ms |
12636 KB |
Output is correct |
35 |
Correct |
42 ms |
12636 KB |
Output is correct |
36 |
Correct |
41 ms |
12632 KB |
Output is correct |
37 |
Correct |
44 ms |
12636 KB |
Output is correct |
38 |
Correct |
44 ms |
12892 KB |
Output is correct |
39 |
Correct |
43 ms |
12636 KB |
Output is correct |
40 |
Correct |
46 ms |
12852 KB |
Output is correct |
41 |
Correct |
44 ms |
12888 KB |
Output is correct |
42 |
Correct |
45 ms |
12852 KB |
Output is correct |
43 |
Correct |
35 ms |
12880 KB |
Output is correct |
44 |
Correct |
42 ms |
12636 KB |
Output is correct |
45 |
Correct |
57 ms |
12864 KB |
Output is correct |
46 |
Correct |
46 ms |
12892 KB |
Output is correct |
47 |
Correct |
37 ms |
12636 KB |
Output is correct |
48 |
Correct |
42 ms |
12636 KB |
Output is correct |
49 |
Correct |
53 ms |
12860 KB |
Output is correct |
50 |
Correct |
50 ms |
12860 KB |
Output is correct |
51 |
Correct |
38 ms |
12856 KB |
Output is correct |
52 |
Correct |
40 ms |
12864 KB |
Output is correct |
53 |
Correct |
43 ms |
12848 KB |
Output is correct |
54 |
Correct |
42 ms |
12892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
70 ms |
22760 KB |
Output is correct |
4 |
Correct |
68 ms |
21736 KB |
Output is correct |
5 |
Correct |
70 ms |
22476 KB |
Output is correct |
6 |
Correct |
65 ms |
21680 KB |
Output is correct |
7 |
Correct |
77 ms |
21576 KB |
Output is correct |
8 |
Correct |
63 ms |
21064 KB |
Output is correct |
9 |
Correct |
61 ms |
21192 KB |
Output is correct |
10 |
Correct |
72 ms |
22000 KB |
Output is correct |
11 |
Correct |
65 ms |
21704 KB |
Output is correct |
12 |
Correct |
72 ms |
22248 KB |
Output is correct |
13 |
Correct |
65 ms |
21140 KB |
Output is correct |
14 |
Correct |
78 ms |
21412 KB |
Output is correct |
15 |
Correct |
66 ms |
21696 KB |
Output is correct |
16 |
Correct |
68 ms |
22400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
3 ms |
12768 KB |
Output is correct |
4 |
Correct |
2 ms |
12632 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12632 KB |
Output is correct |
8 |
Correct |
3 ms |
12636 KB |
Output is correct |
9 |
Correct |
3 ms |
12636 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
4 ms |
12788 KB |
Output is correct |
12 |
Correct |
3 ms |
12632 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
3 ms |
12660 KB |
Output is correct |
17 |
Correct |
3 ms |
12632 KB |
Output is correct |
18 |
Correct |
3 ms |
12776 KB |
Output is correct |
19 |
Correct |
4 ms |
12636 KB |
Output is correct |
20 |
Correct |
3 ms |
12636 KB |
Output is correct |
21 |
Correct |
4 ms |
12632 KB |
Output is correct |
22 |
Correct |
3 ms |
12636 KB |
Output is correct |
23 |
Correct |
4 ms |
12636 KB |
Output is correct |
24 |
Correct |
4 ms |
12636 KB |
Output is correct |
25 |
Correct |
3 ms |
12636 KB |
Output is correct |
26 |
Correct |
3 ms |
12632 KB |
Output is correct |
27 |
Correct |
3 ms |
12636 KB |
Output is correct |
28 |
Correct |
3 ms |
12636 KB |
Output is correct |
29 |
Correct |
70 ms |
22760 KB |
Output is correct |
30 |
Correct |
68 ms |
21736 KB |
Output is correct |
31 |
Correct |
70 ms |
22476 KB |
Output is correct |
32 |
Correct |
65 ms |
21680 KB |
Output is correct |
33 |
Correct |
77 ms |
21576 KB |
Output is correct |
34 |
Correct |
63 ms |
21064 KB |
Output is correct |
35 |
Correct |
61 ms |
21192 KB |
Output is correct |
36 |
Correct |
72 ms |
22000 KB |
Output is correct |
37 |
Correct |
65 ms |
21704 KB |
Output is correct |
38 |
Correct |
72 ms |
22248 KB |
Output is correct |
39 |
Correct |
65 ms |
21140 KB |
Output is correct |
40 |
Correct |
78 ms |
21412 KB |
Output is correct |
41 |
Correct |
66 ms |
21696 KB |
Output is correct |
42 |
Correct |
68 ms |
22400 KB |
Output is correct |
43 |
Correct |
953 ms |
22924 KB |
Output is correct |
44 |
Correct |
1282 ms |
22800 KB |
Output is correct |
45 |
Correct |
1294 ms |
22276 KB |
Output is correct |
46 |
Correct |
1169 ms |
21728 KB |
Output is correct |
47 |
Correct |
1268 ms |
22084 KB |
Output is correct |
48 |
Correct |
1260 ms |
22516 KB |
Output is correct |
49 |
Correct |
1434 ms |
22876 KB |
Output is correct |
50 |
Correct |
1272 ms |
21400 KB |
Output is correct |
51 |
Correct |
1312 ms |
21948 KB |
Output is correct |
52 |
Correct |
1281 ms |
22380 KB |
Output is correct |
53 |
Correct |
668 ms |
21136 KB |
Output is correct |
54 |
Correct |
1069 ms |
21596 KB |
Output is correct |
55 |
Correct |
1352 ms |
21976 KB |
Output is correct |
56 |
Correct |
1488 ms |
22684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
3 ms |
12768 KB |
Output is correct |
4 |
Correct |
2 ms |
12632 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12632 KB |
Output is correct |
8 |
Correct |
3 ms |
12636 KB |
Output is correct |
9 |
Correct |
3 ms |
12636 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
4 ms |
12788 KB |
Output is correct |
12 |
Correct |
3 ms |
12632 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
3 ms |
12660 KB |
Output is correct |
17 |
Correct |
3 ms |
12632 KB |
Output is correct |
18 |
Correct |
3 ms |
12776 KB |
Output is correct |
19 |
Correct |
4 ms |
12636 KB |
Output is correct |
20 |
Correct |
3 ms |
12636 KB |
Output is correct |
21 |
Correct |
4 ms |
12632 KB |
Output is correct |
22 |
Correct |
3 ms |
12636 KB |
Output is correct |
23 |
Correct |
4 ms |
12636 KB |
Output is correct |
24 |
Correct |
4 ms |
12636 KB |
Output is correct |
25 |
Correct |
3 ms |
12636 KB |
Output is correct |
26 |
Correct |
3 ms |
12632 KB |
Output is correct |
27 |
Correct |
3 ms |
12636 KB |
Output is correct |
28 |
Correct |
3 ms |
12636 KB |
Output is correct |
29 |
Correct |
13 ms |
12636 KB |
Output is correct |
30 |
Correct |
35 ms |
12636 KB |
Output is correct |
31 |
Correct |
50 ms |
12636 KB |
Output is correct |
32 |
Correct |
39 ms |
12632 KB |
Output is correct |
33 |
Correct |
42 ms |
12852 KB |
Output is correct |
34 |
Correct |
41 ms |
12636 KB |
Output is correct |
35 |
Correct |
42 ms |
12636 KB |
Output is correct |
36 |
Correct |
41 ms |
12632 KB |
Output is correct |
37 |
Correct |
44 ms |
12636 KB |
Output is correct |
38 |
Correct |
44 ms |
12892 KB |
Output is correct |
39 |
Correct |
43 ms |
12636 KB |
Output is correct |
40 |
Correct |
46 ms |
12852 KB |
Output is correct |
41 |
Correct |
44 ms |
12888 KB |
Output is correct |
42 |
Correct |
45 ms |
12852 KB |
Output is correct |
43 |
Correct |
35 ms |
12880 KB |
Output is correct |
44 |
Correct |
42 ms |
12636 KB |
Output is correct |
45 |
Correct |
57 ms |
12864 KB |
Output is correct |
46 |
Correct |
46 ms |
12892 KB |
Output is correct |
47 |
Correct |
37 ms |
12636 KB |
Output is correct |
48 |
Correct |
42 ms |
12636 KB |
Output is correct |
49 |
Correct |
53 ms |
12860 KB |
Output is correct |
50 |
Correct |
50 ms |
12860 KB |
Output is correct |
51 |
Correct |
38 ms |
12856 KB |
Output is correct |
52 |
Correct |
40 ms |
12864 KB |
Output is correct |
53 |
Correct |
43 ms |
12848 KB |
Output is correct |
54 |
Correct |
42 ms |
12892 KB |
Output is correct |
55 |
Execution timed out |
2005 ms |
15804 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
3 ms |
12768 KB |
Output is correct |
4 |
Correct |
2 ms |
12632 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12632 KB |
Output is correct |
8 |
Correct |
3 ms |
12636 KB |
Output is correct |
9 |
Correct |
3 ms |
12636 KB |
Output is correct |
10 |
Correct |
3 ms |
12636 KB |
Output is correct |
11 |
Correct |
4 ms |
12788 KB |
Output is correct |
12 |
Correct |
3 ms |
12632 KB |
Output is correct |
13 |
Correct |
3 ms |
12636 KB |
Output is correct |
14 |
Correct |
3 ms |
12636 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
3 ms |
12660 KB |
Output is correct |
17 |
Correct |
3 ms |
12632 KB |
Output is correct |
18 |
Correct |
3 ms |
12776 KB |
Output is correct |
19 |
Correct |
4 ms |
12636 KB |
Output is correct |
20 |
Correct |
3 ms |
12636 KB |
Output is correct |
21 |
Correct |
4 ms |
12632 KB |
Output is correct |
22 |
Correct |
3 ms |
12636 KB |
Output is correct |
23 |
Correct |
4 ms |
12636 KB |
Output is correct |
24 |
Correct |
4 ms |
12636 KB |
Output is correct |
25 |
Correct |
3 ms |
12636 KB |
Output is correct |
26 |
Correct |
3 ms |
12632 KB |
Output is correct |
27 |
Correct |
3 ms |
12636 KB |
Output is correct |
28 |
Correct |
3 ms |
12636 KB |
Output is correct |
29 |
Correct |
13 ms |
12636 KB |
Output is correct |
30 |
Correct |
35 ms |
12636 KB |
Output is correct |
31 |
Correct |
50 ms |
12636 KB |
Output is correct |
32 |
Correct |
39 ms |
12632 KB |
Output is correct |
33 |
Correct |
42 ms |
12852 KB |
Output is correct |
34 |
Correct |
41 ms |
12636 KB |
Output is correct |
35 |
Correct |
42 ms |
12636 KB |
Output is correct |
36 |
Correct |
41 ms |
12632 KB |
Output is correct |
37 |
Correct |
44 ms |
12636 KB |
Output is correct |
38 |
Correct |
44 ms |
12892 KB |
Output is correct |
39 |
Correct |
43 ms |
12636 KB |
Output is correct |
40 |
Correct |
46 ms |
12852 KB |
Output is correct |
41 |
Correct |
44 ms |
12888 KB |
Output is correct |
42 |
Correct |
45 ms |
12852 KB |
Output is correct |
43 |
Correct |
35 ms |
12880 KB |
Output is correct |
44 |
Correct |
42 ms |
12636 KB |
Output is correct |
45 |
Correct |
57 ms |
12864 KB |
Output is correct |
46 |
Correct |
46 ms |
12892 KB |
Output is correct |
47 |
Correct |
37 ms |
12636 KB |
Output is correct |
48 |
Correct |
42 ms |
12636 KB |
Output is correct |
49 |
Correct |
53 ms |
12860 KB |
Output is correct |
50 |
Correct |
50 ms |
12860 KB |
Output is correct |
51 |
Correct |
38 ms |
12856 KB |
Output is correct |
52 |
Correct |
40 ms |
12864 KB |
Output is correct |
53 |
Correct |
43 ms |
12848 KB |
Output is correct |
54 |
Correct |
42 ms |
12892 KB |
Output is correct |
55 |
Correct |
70 ms |
22760 KB |
Output is correct |
56 |
Correct |
68 ms |
21736 KB |
Output is correct |
57 |
Correct |
70 ms |
22476 KB |
Output is correct |
58 |
Correct |
65 ms |
21680 KB |
Output is correct |
59 |
Correct |
77 ms |
21576 KB |
Output is correct |
60 |
Correct |
63 ms |
21064 KB |
Output is correct |
61 |
Correct |
61 ms |
21192 KB |
Output is correct |
62 |
Correct |
72 ms |
22000 KB |
Output is correct |
63 |
Correct |
65 ms |
21704 KB |
Output is correct |
64 |
Correct |
72 ms |
22248 KB |
Output is correct |
65 |
Correct |
65 ms |
21140 KB |
Output is correct |
66 |
Correct |
78 ms |
21412 KB |
Output is correct |
67 |
Correct |
66 ms |
21696 KB |
Output is correct |
68 |
Correct |
68 ms |
22400 KB |
Output is correct |
69 |
Correct |
953 ms |
22924 KB |
Output is correct |
70 |
Correct |
1282 ms |
22800 KB |
Output is correct |
71 |
Correct |
1294 ms |
22276 KB |
Output is correct |
72 |
Correct |
1169 ms |
21728 KB |
Output is correct |
73 |
Correct |
1268 ms |
22084 KB |
Output is correct |
74 |
Correct |
1260 ms |
22516 KB |
Output is correct |
75 |
Correct |
1434 ms |
22876 KB |
Output is correct |
76 |
Correct |
1272 ms |
21400 KB |
Output is correct |
77 |
Correct |
1312 ms |
21948 KB |
Output is correct |
78 |
Correct |
1281 ms |
22380 KB |
Output is correct |
79 |
Correct |
668 ms |
21136 KB |
Output is correct |
80 |
Correct |
1069 ms |
21596 KB |
Output is correct |
81 |
Correct |
1352 ms |
21976 KB |
Output is correct |
82 |
Correct |
1488 ms |
22684 KB |
Output is correct |
83 |
Execution timed out |
2005 ms |
15804 KB |
Time limit exceeded |
84 |
Halted |
0 ms |
0 KB |
- |