#include <bits/stdc++.h>
using namespace std;
int n;int m;int Q;
int ar[400005];
int br[400005];
int uf[200005];
int isbip;
int sz[200005];
int ufv[200005];
stack<int>stk;
stack<int>stkv;
stack<int>stkbp;
int finv(int x){
if(uf[x]==x){return 0;}
return (ufv[x]+finv(uf[x]))&1;
}
int fin(int x){
if(uf[x]==x){return x;}
int v=(ufv[x]+finv(uf[x]))&1;
ufv[x]=v;
uf[x]=fin(uf[x]);
return uf[x];
}
void mrg(int a,int b){
int pa=fin(a);int pb=fin(b);
if(pa==pb){
// stk.push(0);stkbp.push(isbip);
if(finv(a)==finv(b)){
isbip=0;
}
return;
}
//stkbp.push(isbip);
if(sz[pa]<sz[pb]){swap(pa,pb);swap(a,b);}
int va=finv(a);int vb=finv(b);
if(va==vb){
// stkv.push(1);
ufv[pb]=1;
uf[pb]=pa;
sz[pa]+=sz[pb];
}else{
//stkv.push(0);
ufv[pb]=0;
uf[pb]=pa;
sz[pa]+=sz[pb];
}
//stk.push(pb);
}
void rollback(){
int pb=stk.top();
if(pb==0){
stk.pop();//stkv.pop();
isbip=stkbp.top();
stkbp.pop();
return;
}
isbip=stkbp.top();
stk.pop();stkbp.pop();
int pa=uf[pb];
sz[pa]-=sz[pb];
uf[pb]=pb;
ufv[pb]=0;
}
int lar[200005];int rar[200005];int lpl[200005];
void precalc(){
for(int i=1;i<=n;i++){
uf[i]=i;
ufv[i]=0;
sz[i]=1;
}
while(stk.size()){stk.pop();}
while(stkbp.size()){stkbp.pop();}
}
void dolid(int lid){
precalc();
isbip=1;
lpl[lid]=0;
for(int i=m+lid-1;i>=lid-1;i--){
mrg(ar[i],br[i]);
if(!isbip){
lpl[lid]=i;break;
}
}
}
signed main(){
cin>>n>>m>>Q;
for(int i=1;i<=m;i++){
cin>>ar[i]>>br[i];
ar[i+m]=ar[i];
br[i+m]=br[i];
}
set<int>st;
for(int i=1;i<=Q;i++){
cin>>lar[i]>>rar[i];
st.insert(lar[i]);
}
for(auto it=st.begin();it!=st.end();it++){
int v=*it;
dolid(v);
}
for(int i=1;i<=Q;i++){
if(rar[i]<lpl[lar[i]]){
cout<<"YES\n";
}else{
cout<<"NO\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
13 ms |
340 KB |
Output is correct |
30 |
Correct |
19 ms |
464 KB |
Output is correct |
31 |
Correct |
18 ms |
468 KB |
Output is correct |
32 |
Correct |
11 ms |
472 KB |
Output is correct |
33 |
Correct |
7 ms |
468 KB |
Output is correct |
34 |
Correct |
19 ms |
472 KB |
Output is correct |
35 |
Correct |
25 ms |
468 KB |
Output is correct |
36 |
Correct |
23 ms |
468 KB |
Output is correct |
37 |
Correct |
40 ms |
480 KB |
Output is correct |
38 |
Correct |
49 ms |
476 KB |
Output is correct |
39 |
Correct |
21 ms |
468 KB |
Output is correct |
40 |
Correct |
13 ms |
460 KB |
Output is correct |
41 |
Correct |
12 ms |
512 KB |
Output is correct |
42 |
Correct |
12 ms |
468 KB |
Output is correct |
43 |
Correct |
14 ms |
460 KB |
Output is correct |
44 |
Correct |
15 ms |
468 KB |
Output is correct |
45 |
Correct |
16 ms |
472 KB |
Output is correct |
46 |
Correct |
21 ms |
476 KB |
Output is correct |
47 |
Correct |
22 ms |
468 KB |
Output is correct |
48 |
Correct |
17 ms |
468 KB |
Output is correct |
49 |
Correct |
18 ms |
460 KB |
Output is correct |
50 |
Correct |
25 ms |
480 KB |
Output is correct |
51 |
Correct |
15 ms |
464 KB |
Output is correct |
52 |
Correct |
15 ms |
468 KB |
Output is correct |
53 |
Correct |
16 ms |
472 KB |
Output is correct |
54 |
Correct |
25 ms |
472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
167 ms |
6796 KB |
Output is correct |
4 |
Correct |
161 ms |
7912 KB |
Output is correct |
5 |
Correct |
173 ms |
7680 KB |
Output is correct |
6 |
Correct |
170 ms |
6728 KB |
Output is correct |
7 |
Correct |
170 ms |
6808 KB |
Output is correct |
8 |
Correct |
151 ms |
6484 KB |
Output is correct |
9 |
Correct |
148 ms |
6940 KB |
Output is correct |
10 |
Correct |
171 ms |
8012 KB |
Output is correct |
11 |
Correct |
165 ms |
6696 KB |
Output is correct |
12 |
Correct |
170 ms |
7628 KB |
Output is correct |
13 |
Correct |
163 ms |
5744 KB |
Output is correct |
14 |
Correct |
177 ms |
6332 KB |
Output is correct |
15 |
Correct |
175 ms |
7220 KB |
Output is correct |
16 |
Correct |
171 ms |
7880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
167 ms |
6796 KB |
Output is correct |
30 |
Correct |
161 ms |
7912 KB |
Output is correct |
31 |
Correct |
173 ms |
7680 KB |
Output is correct |
32 |
Correct |
170 ms |
6728 KB |
Output is correct |
33 |
Correct |
170 ms |
6808 KB |
Output is correct |
34 |
Correct |
151 ms |
6484 KB |
Output is correct |
35 |
Correct |
148 ms |
6940 KB |
Output is correct |
36 |
Correct |
171 ms |
8012 KB |
Output is correct |
37 |
Correct |
165 ms |
6696 KB |
Output is correct |
38 |
Correct |
170 ms |
7628 KB |
Output is correct |
39 |
Correct |
163 ms |
5744 KB |
Output is correct |
40 |
Correct |
177 ms |
6332 KB |
Output is correct |
41 |
Correct |
175 ms |
7220 KB |
Output is correct |
42 |
Correct |
171 ms |
7880 KB |
Output is correct |
43 |
Correct |
647 ms |
6696 KB |
Output is correct |
44 |
Correct |
1473 ms |
7856 KB |
Output is correct |
45 |
Correct |
1343 ms |
7856 KB |
Output is correct |
46 |
Correct |
231 ms |
6812 KB |
Output is correct |
47 |
Correct |
291 ms |
6824 KB |
Output is correct |
48 |
Correct |
528 ms |
6956 KB |
Output is correct |
49 |
Correct |
835 ms |
8112 KB |
Output is correct |
50 |
Correct |
863 ms |
6460 KB |
Output is correct |
51 |
Correct |
777 ms |
7164 KB |
Output is correct |
52 |
Correct |
709 ms |
7856 KB |
Output is correct |
53 |
Correct |
489 ms |
5880 KB |
Output is correct |
54 |
Correct |
527 ms |
6584 KB |
Output is correct |
55 |
Correct |
691 ms |
7292 KB |
Output is correct |
56 |
Correct |
872 ms |
7852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
13 ms |
340 KB |
Output is correct |
30 |
Correct |
19 ms |
464 KB |
Output is correct |
31 |
Correct |
18 ms |
468 KB |
Output is correct |
32 |
Correct |
11 ms |
472 KB |
Output is correct |
33 |
Correct |
7 ms |
468 KB |
Output is correct |
34 |
Correct |
19 ms |
472 KB |
Output is correct |
35 |
Correct |
25 ms |
468 KB |
Output is correct |
36 |
Correct |
23 ms |
468 KB |
Output is correct |
37 |
Correct |
40 ms |
480 KB |
Output is correct |
38 |
Correct |
49 ms |
476 KB |
Output is correct |
39 |
Correct |
21 ms |
468 KB |
Output is correct |
40 |
Correct |
13 ms |
460 KB |
Output is correct |
41 |
Correct |
12 ms |
512 KB |
Output is correct |
42 |
Correct |
12 ms |
468 KB |
Output is correct |
43 |
Correct |
14 ms |
460 KB |
Output is correct |
44 |
Correct |
15 ms |
468 KB |
Output is correct |
45 |
Correct |
16 ms |
472 KB |
Output is correct |
46 |
Correct |
21 ms |
476 KB |
Output is correct |
47 |
Correct |
22 ms |
468 KB |
Output is correct |
48 |
Correct |
17 ms |
468 KB |
Output is correct |
49 |
Correct |
18 ms |
460 KB |
Output is correct |
50 |
Correct |
25 ms |
480 KB |
Output is correct |
51 |
Correct |
15 ms |
464 KB |
Output is correct |
52 |
Correct |
15 ms |
468 KB |
Output is correct |
53 |
Correct |
16 ms |
472 KB |
Output is correct |
54 |
Correct |
25 ms |
472 KB |
Output is correct |
55 |
Execution timed out |
2081 ms |
5012 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
13 ms |
340 KB |
Output is correct |
30 |
Correct |
19 ms |
464 KB |
Output is correct |
31 |
Correct |
18 ms |
468 KB |
Output is correct |
32 |
Correct |
11 ms |
472 KB |
Output is correct |
33 |
Correct |
7 ms |
468 KB |
Output is correct |
34 |
Correct |
19 ms |
472 KB |
Output is correct |
35 |
Correct |
25 ms |
468 KB |
Output is correct |
36 |
Correct |
23 ms |
468 KB |
Output is correct |
37 |
Correct |
40 ms |
480 KB |
Output is correct |
38 |
Correct |
49 ms |
476 KB |
Output is correct |
39 |
Correct |
21 ms |
468 KB |
Output is correct |
40 |
Correct |
13 ms |
460 KB |
Output is correct |
41 |
Correct |
12 ms |
512 KB |
Output is correct |
42 |
Correct |
12 ms |
468 KB |
Output is correct |
43 |
Correct |
14 ms |
460 KB |
Output is correct |
44 |
Correct |
15 ms |
468 KB |
Output is correct |
45 |
Correct |
16 ms |
472 KB |
Output is correct |
46 |
Correct |
21 ms |
476 KB |
Output is correct |
47 |
Correct |
22 ms |
468 KB |
Output is correct |
48 |
Correct |
17 ms |
468 KB |
Output is correct |
49 |
Correct |
18 ms |
460 KB |
Output is correct |
50 |
Correct |
25 ms |
480 KB |
Output is correct |
51 |
Correct |
15 ms |
464 KB |
Output is correct |
52 |
Correct |
15 ms |
468 KB |
Output is correct |
53 |
Correct |
16 ms |
472 KB |
Output is correct |
54 |
Correct |
25 ms |
472 KB |
Output is correct |
55 |
Correct |
167 ms |
6796 KB |
Output is correct |
56 |
Correct |
161 ms |
7912 KB |
Output is correct |
57 |
Correct |
173 ms |
7680 KB |
Output is correct |
58 |
Correct |
170 ms |
6728 KB |
Output is correct |
59 |
Correct |
170 ms |
6808 KB |
Output is correct |
60 |
Correct |
151 ms |
6484 KB |
Output is correct |
61 |
Correct |
148 ms |
6940 KB |
Output is correct |
62 |
Correct |
171 ms |
8012 KB |
Output is correct |
63 |
Correct |
165 ms |
6696 KB |
Output is correct |
64 |
Correct |
170 ms |
7628 KB |
Output is correct |
65 |
Correct |
163 ms |
5744 KB |
Output is correct |
66 |
Correct |
177 ms |
6332 KB |
Output is correct |
67 |
Correct |
175 ms |
7220 KB |
Output is correct |
68 |
Correct |
171 ms |
7880 KB |
Output is correct |
69 |
Correct |
647 ms |
6696 KB |
Output is correct |
70 |
Correct |
1473 ms |
7856 KB |
Output is correct |
71 |
Correct |
1343 ms |
7856 KB |
Output is correct |
72 |
Correct |
231 ms |
6812 KB |
Output is correct |
73 |
Correct |
291 ms |
6824 KB |
Output is correct |
74 |
Correct |
528 ms |
6956 KB |
Output is correct |
75 |
Correct |
835 ms |
8112 KB |
Output is correct |
76 |
Correct |
863 ms |
6460 KB |
Output is correct |
77 |
Correct |
777 ms |
7164 KB |
Output is correct |
78 |
Correct |
709 ms |
7856 KB |
Output is correct |
79 |
Correct |
489 ms |
5880 KB |
Output is correct |
80 |
Correct |
527 ms |
6584 KB |
Output is correct |
81 |
Correct |
691 ms |
7292 KB |
Output is correct |
82 |
Correct |
872 ms |
7852 KB |
Output is correct |
83 |
Execution timed out |
2081 ms |
5012 KB |
Time limit exceeded |
84 |
Halted |
0 ms |
0 KB |
- |