#include<bits/stdc++.h>
#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
using namespace std;
const int N = 2e5+10;
int n,m,q,fre[N],lz[N],p[N],sz[N];
int ans[N];
pii d[N];
vector<int> ad[N];
//sub1
bool qu1(int l,int r)
{
bool ok = 0;
forinc(i,1,n) ad[i].clear();
forinc(i,1,m)
{
if(l<=i && i<=r) continue;
int x,y;
tie(x,y) = d[i];
ad[x].pb(y);
ad[y].pb(x);
}
for(int i=1; i<=n; i++) fre[i] = -1;
for(int i=1; i<=n; i++)
{
if(fre[i] == -1)
{
queue<int> q;
q.push(i);
fre[i] = 0;
while(q.size())
{
int u = q.front();
q.pop();
for(int v:ad[u])
{
if(fre[v] == fre[u]) return true;
if(fre[v] != -1) continue;
fre[v] = 1 - fre[u];
q.push(v);
}
}
}
}
return false;
}
//sub2
struct node
{
int l,r,id;
}qu[N];
bool cmp(node a,node b)
{
return a.r > b.r;
}
int pa(int v,int &c)
{
c ^= lz[v];
if(p[v] == v) return v;
return pa(p[v], c);
}
void join(int a,int b)
{
int ca = 0;
int cb = 0;
a = pa(a,ca);
b = pa(b,cb);
if(a != b)
{
if(sz[a] < sz[b]) swap(a,b);
sz[a] += sz[b];
p[b] = a;
if(ca == cb) lz[b] = 1;
}
}
bool check(int a,int b)
{
int ca = 0;
int cb = 0;
a = pa(a,ca);
b = pa(b,cb);
if(a == b && ca == cb) return true;
return false;
}
//bool qu2(int l,int r)
//{
// for(int i=1; i<=m; i++)
// {
// if(l<=i && i<=r) continue;
// if(check(d[i].fi, d[i].se)) return true;
// join(d[i].fi, d[i].se);
// }
// return false;
//}
int32_t main()
{
if(fopen("task.inp","r"))
{
freopen("task.inp","r",stdin);
freopen("task.out","w",stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>q;
forinc(i,1,m)
{
int x,y;
cin>>x>>y;
d[i] = {x,y};
}
if(n<=2000 && m <= 2000 && q <= 2000)
{
while(q--)
{
int l,r;
cin>>l>>r;
cout<< (qu1(l,r) ? "YES\n" : "NO\n");
}
return 0;
}
forinc(i,1,n)
{
sz[i] = 1;
p[i] = i;
lz[i] = 0;
}
forinc(i,1,q)
{
int l,r;
cin>>l>>r;
qu[i] = {l,r,i};
}
sort(qu + 1 , qu + q + 1,cmp);
bool ok=0;
for(int i = m; i>qu[1].r ;i--)
{
if(check(d[i].fi , d[i].se)) ok=1;
join(d[i].fi,d[i].se);
}
ans[qu[1].id] = ok;
for(int i=2;i<=q;i++)
{
for(int j = qu[i-1].r;j>qu[i].r;j--)
{
if(check(d[j].fi,d[j].se)) ok = 1;
join(d[j].fi , d[j].se);
}
ans[qu[i].id] = ok;
}
forinc(i,1,q) cout<<(ans[i] ? "YES\n" : "NO\n");
}
Compilation message
Joker.cpp: In function 'bool qu1(long long int, long long int)':
Joker.cpp:17:10: warning: unused variable 'ok' [-Wunused-variable]
17 | bool ok = 0;
| ^~
Joker.cpp: In function 'int32_t main()':
Joker.cpp:105:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
105 | freopen("task.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
106 | freopen("task.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
3 ms |
5172 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
3 ms |
4956 KB |
Output is correct |
12 |
Correct |
4 ms |
4952 KB |
Output is correct |
13 |
Correct |
3 ms |
4956 KB |
Output is correct |
14 |
Correct |
3 ms |
4952 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
3 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
5196 KB |
Output is correct |
18 |
Correct |
4 ms |
4956 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4952 KB |
Output is correct |
21 |
Correct |
2 ms |
5168 KB |
Output is correct |
22 |
Correct |
3 ms |
4956 KB |
Output is correct |
23 |
Correct |
3 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
3 ms |
4956 KB |
Output is correct |
26 |
Correct |
2 ms |
4956 KB |
Output is correct |
27 |
Correct |
3 ms |
4956 KB |
Output is correct |
28 |
Correct |
3 ms |
5176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
3 ms |
5172 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
3 ms |
4956 KB |
Output is correct |
12 |
Correct |
4 ms |
4952 KB |
Output is correct |
13 |
Correct |
3 ms |
4956 KB |
Output is correct |
14 |
Correct |
3 ms |
4952 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
3 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
5196 KB |
Output is correct |
18 |
Correct |
4 ms |
4956 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4952 KB |
Output is correct |
21 |
Correct |
2 ms |
5168 KB |
Output is correct |
22 |
Correct |
3 ms |
4956 KB |
Output is correct |
23 |
Correct |
3 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
3 ms |
4956 KB |
Output is correct |
26 |
Correct |
2 ms |
4956 KB |
Output is correct |
27 |
Correct |
3 ms |
4956 KB |
Output is correct |
28 |
Correct |
3 ms |
5176 KB |
Output is correct |
29 |
Correct |
95 ms |
5464 KB |
Output is correct |
30 |
Correct |
66 ms |
5208 KB |
Output is correct |
31 |
Correct |
48 ms |
5208 KB |
Output is correct |
32 |
Correct |
27 ms |
5212 KB |
Output is correct |
33 |
Correct |
18 ms |
5324 KB |
Output is correct |
34 |
Correct |
53 ms |
5320 KB |
Output is correct |
35 |
Correct |
70 ms |
5208 KB |
Output is correct |
36 |
Correct |
37 ms |
5208 KB |
Output is correct |
37 |
Correct |
91 ms |
5212 KB |
Output is correct |
38 |
Correct |
77 ms |
5328 KB |
Output is correct |
39 |
Correct |
72 ms |
5308 KB |
Output is correct |
40 |
Correct |
41 ms |
5208 KB |
Output is correct |
41 |
Correct |
38 ms |
5208 KB |
Output is correct |
42 |
Correct |
37 ms |
5208 KB |
Output is correct |
43 |
Correct |
18 ms |
5208 KB |
Output is correct |
44 |
Correct |
21 ms |
5208 KB |
Output is correct |
45 |
Correct |
25 ms |
5212 KB |
Output is correct |
46 |
Correct |
30 ms |
5212 KB |
Output is correct |
47 |
Correct |
33 ms |
5212 KB |
Output is correct |
48 |
Correct |
37 ms |
5212 KB |
Output is correct |
49 |
Correct |
54 ms |
5208 KB |
Output is correct |
50 |
Correct |
68 ms |
5212 KB |
Output is correct |
51 |
Correct |
27 ms |
5212 KB |
Output is correct |
52 |
Correct |
35 ms |
5208 KB |
Output is correct |
53 |
Correct |
47 ms |
5324 KB |
Output is correct |
54 |
Correct |
67 ms |
5212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
74 ms |
19668 KB |
Output is correct |
4 |
Correct |
70 ms |
21840 KB |
Output is correct |
5 |
Correct |
76 ms |
21584 KB |
Output is correct |
6 |
Correct |
70 ms |
19796 KB |
Output is correct |
7 |
Correct |
74 ms |
19796 KB |
Output is correct |
8 |
Correct |
68 ms |
18516 KB |
Output is correct |
9 |
Correct |
80 ms |
19536 KB |
Output is correct |
10 |
Correct |
75 ms |
22056 KB |
Output is correct |
11 |
Correct |
71 ms |
19792 KB |
Output is correct |
12 |
Correct |
71 ms |
21604 KB |
Output is correct |
13 |
Correct |
70 ms |
17876 KB |
Output is correct |
14 |
Correct |
76 ms |
18772 KB |
Output is correct |
15 |
Correct |
74 ms |
20556 KB |
Output is correct |
16 |
Correct |
74 ms |
22132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
3 ms |
5172 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
3 ms |
4956 KB |
Output is correct |
12 |
Correct |
4 ms |
4952 KB |
Output is correct |
13 |
Correct |
3 ms |
4956 KB |
Output is correct |
14 |
Correct |
3 ms |
4952 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
3 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
5196 KB |
Output is correct |
18 |
Correct |
4 ms |
4956 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4952 KB |
Output is correct |
21 |
Correct |
2 ms |
5168 KB |
Output is correct |
22 |
Correct |
3 ms |
4956 KB |
Output is correct |
23 |
Correct |
3 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
3 ms |
4956 KB |
Output is correct |
26 |
Correct |
2 ms |
4956 KB |
Output is correct |
27 |
Correct |
3 ms |
4956 KB |
Output is correct |
28 |
Correct |
3 ms |
5176 KB |
Output is correct |
29 |
Correct |
74 ms |
19668 KB |
Output is correct |
30 |
Correct |
70 ms |
21840 KB |
Output is correct |
31 |
Correct |
76 ms |
21584 KB |
Output is correct |
32 |
Correct |
70 ms |
19796 KB |
Output is correct |
33 |
Correct |
74 ms |
19796 KB |
Output is correct |
34 |
Correct |
68 ms |
18516 KB |
Output is correct |
35 |
Correct |
80 ms |
19536 KB |
Output is correct |
36 |
Correct |
75 ms |
22056 KB |
Output is correct |
37 |
Correct |
71 ms |
19792 KB |
Output is correct |
38 |
Correct |
71 ms |
21604 KB |
Output is correct |
39 |
Correct |
70 ms |
17876 KB |
Output is correct |
40 |
Correct |
76 ms |
18772 KB |
Output is correct |
41 |
Correct |
74 ms |
20556 KB |
Output is correct |
42 |
Correct |
74 ms |
22132 KB |
Output is correct |
43 |
Incorrect |
76 ms |
19760 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
3 ms |
5172 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
3 ms |
4956 KB |
Output is correct |
12 |
Correct |
4 ms |
4952 KB |
Output is correct |
13 |
Correct |
3 ms |
4956 KB |
Output is correct |
14 |
Correct |
3 ms |
4952 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
3 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
5196 KB |
Output is correct |
18 |
Correct |
4 ms |
4956 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4952 KB |
Output is correct |
21 |
Correct |
2 ms |
5168 KB |
Output is correct |
22 |
Correct |
3 ms |
4956 KB |
Output is correct |
23 |
Correct |
3 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
3 ms |
4956 KB |
Output is correct |
26 |
Correct |
2 ms |
4956 KB |
Output is correct |
27 |
Correct |
3 ms |
4956 KB |
Output is correct |
28 |
Correct |
3 ms |
5176 KB |
Output is correct |
29 |
Correct |
95 ms |
5464 KB |
Output is correct |
30 |
Correct |
66 ms |
5208 KB |
Output is correct |
31 |
Correct |
48 ms |
5208 KB |
Output is correct |
32 |
Correct |
27 ms |
5212 KB |
Output is correct |
33 |
Correct |
18 ms |
5324 KB |
Output is correct |
34 |
Correct |
53 ms |
5320 KB |
Output is correct |
35 |
Correct |
70 ms |
5208 KB |
Output is correct |
36 |
Correct |
37 ms |
5208 KB |
Output is correct |
37 |
Correct |
91 ms |
5212 KB |
Output is correct |
38 |
Correct |
77 ms |
5328 KB |
Output is correct |
39 |
Correct |
72 ms |
5308 KB |
Output is correct |
40 |
Correct |
41 ms |
5208 KB |
Output is correct |
41 |
Correct |
38 ms |
5208 KB |
Output is correct |
42 |
Correct |
37 ms |
5208 KB |
Output is correct |
43 |
Correct |
18 ms |
5208 KB |
Output is correct |
44 |
Correct |
21 ms |
5208 KB |
Output is correct |
45 |
Correct |
25 ms |
5212 KB |
Output is correct |
46 |
Correct |
30 ms |
5212 KB |
Output is correct |
47 |
Correct |
33 ms |
5212 KB |
Output is correct |
48 |
Correct |
37 ms |
5212 KB |
Output is correct |
49 |
Correct |
54 ms |
5208 KB |
Output is correct |
50 |
Correct |
68 ms |
5212 KB |
Output is correct |
51 |
Correct |
27 ms |
5212 KB |
Output is correct |
52 |
Correct |
35 ms |
5208 KB |
Output is correct |
53 |
Correct |
47 ms |
5324 KB |
Output is correct |
54 |
Correct |
67 ms |
5212 KB |
Output is correct |
55 |
Incorrect |
31 ms |
12096 KB |
Output isn't correct |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
3 ms |
5172 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
3 ms |
4956 KB |
Output is correct |
12 |
Correct |
4 ms |
4952 KB |
Output is correct |
13 |
Correct |
3 ms |
4956 KB |
Output is correct |
14 |
Correct |
3 ms |
4952 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
3 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
5196 KB |
Output is correct |
18 |
Correct |
4 ms |
4956 KB |
Output is correct |
19 |
Correct |
3 ms |
4956 KB |
Output is correct |
20 |
Correct |
3 ms |
4952 KB |
Output is correct |
21 |
Correct |
2 ms |
5168 KB |
Output is correct |
22 |
Correct |
3 ms |
4956 KB |
Output is correct |
23 |
Correct |
3 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
3 ms |
4956 KB |
Output is correct |
26 |
Correct |
2 ms |
4956 KB |
Output is correct |
27 |
Correct |
3 ms |
4956 KB |
Output is correct |
28 |
Correct |
3 ms |
5176 KB |
Output is correct |
29 |
Correct |
95 ms |
5464 KB |
Output is correct |
30 |
Correct |
66 ms |
5208 KB |
Output is correct |
31 |
Correct |
48 ms |
5208 KB |
Output is correct |
32 |
Correct |
27 ms |
5212 KB |
Output is correct |
33 |
Correct |
18 ms |
5324 KB |
Output is correct |
34 |
Correct |
53 ms |
5320 KB |
Output is correct |
35 |
Correct |
70 ms |
5208 KB |
Output is correct |
36 |
Correct |
37 ms |
5208 KB |
Output is correct |
37 |
Correct |
91 ms |
5212 KB |
Output is correct |
38 |
Correct |
77 ms |
5328 KB |
Output is correct |
39 |
Correct |
72 ms |
5308 KB |
Output is correct |
40 |
Correct |
41 ms |
5208 KB |
Output is correct |
41 |
Correct |
38 ms |
5208 KB |
Output is correct |
42 |
Correct |
37 ms |
5208 KB |
Output is correct |
43 |
Correct |
18 ms |
5208 KB |
Output is correct |
44 |
Correct |
21 ms |
5208 KB |
Output is correct |
45 |
Correct |
25 ms |
5212 KB |
Output is correct |
46 |
Correct |
30 ms |
5212 KB |
Output is correct |
47 |
Correct |
33 ms |
5212 KB |
Output is correct |
48 |
Correct |
37 ms |
5212 KB |
Output is correct |
49 |
Correct |
54 ms |
5208 KB |
Output is correct |
50 |
Correct |
68 ms |
5212 KB |
Output is correct |
51 |
Correct |
27 ms |
5212 KB |
Output is correct |
52 |
Correct |
35 ms |
5208 KB |
Output is correct |
53 |
Correct |
47 ms |
5324 KB |
Output is correct |
54 |
Correct |
67 ms |
5212 KB |
Output is correct |
55 |
Correct |
74 ms |
19668 KB |
Output is correct |
56 |
Correct |
70 ms |
21840 KB |
Output is correct |
57 |
Correct |
76 ms |
21584 KB |
Output is correct |
58 |
Correct |
70 ms |
19796 KB |
Output is correct |
59 |
Correct |
74 ms |
19796 KB |
Output is correct |
60 |
Correct |
68 ms |
18516 KB |
Output is correct |
61 |
Correct |
80 ms |
19536 KB |
Output is correct |
62 |
Correct |
75 ms |
22056 KB |
Output is correct |
63 |
Correct |
71 ms |
19792 KB |
Output is correct |
64 |
Correct |
71 ms |
21604 KB |
Output is correct |
65 |
Correct |
70 ms |
17876 KB |
Output is correct |
66 |
Correct |
76 ms |
18772 KB |
Output is correct |
67 |
Correct |
74 ms |
20556 KB |
Output is correct |
68 |
Correct |
74 ms |
22132 KB |
Output is correct |
69 |
Incorrect |
76 ms |
19760 KB |
Output isn't correct |
70 |
Halted |
0 ms |
0 KB |
- |