#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod=1e9+7;
const int M=1e6+10;
const int N=1e3+10;
int n,m,q;
int x[M],y[M];
vector<int> ke[M];
int dd[M];
bool dfs(int u,int p)
{
for(int v:ke[u])
{
if(v==p) continue;
if(dd[v])
{
//cout << dd[v] << " " << dd[u] << "\n";
if(dd[v]%2==dd[u]%2) return true;
}
else
{
dd[v]=dd[u]+1;
if(dfs(v,u)) return true;
}
}
return false;
}
bool check(int mid,int idx)
{
fori(i,1,idx-1)
{
if(x[i]==y[i]) continue;
ke[x[i]].pb(y[i]);
ke[y[i]].pb(x[i]);//if(mid==5) cout << x[i] <<" " << y[i] << "\n";
}
for(int i=mid+1;i<=m;i++)
{
if(x[i]==y[i]) continue;
ke[x[i]].pb(y[i]);//if(mid==5) cout << x[i] <<" " << y[i] << "\n";
ke[y[i]].pb(x[i]);
}
fori(i,1,n) dd[i]=0;
bool ok=0;
fori(i,1,n)
{
if(!dd[i])
{
dd[i]=1;
if(dfs(i,i))
{
ok=1;
break;
}
}
}
//cout << ok << " ";
fori(i,1,n) ke[i].clear();
return ok;
}
vector<ii> Q[M];
int ret[M];
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define task "1"
if(fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin >> n >> m >> q;
fori(i,1,m) cin >> x[i] >> y[i];
int mx=0;
fori(i,1,q)
{
int l,r;
cin >> l >> r;
Q[l].pb({r,i});
mx=max(mx,l);
}
// check(5,4) ;return 0;
fori(i,1,mx)
{
if(Q[i].size()==0) continue;
int l=i,r=m,lim=0;
while(l<=r)
{
int mid=(l+r)/2;
if(check(mid,i))
{
lim=mid;
l=mid+1;
}
else r=mid-1;
}
//cout << lim << " ";
for(ii v:Q[i]) ret[v.se]=(v.fi<=lim) ;
}
fori(i,1,q)
{
if(ret[i]) cout << "YES\n";
else cout << "NO\n";
}
}
Compilation message
Joker.cpp: In function 'int32_t main()':
Joker.cpp:77:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
77 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:78:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
78 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47308 KB |
Output is correct |
2 |
Correct |
25 ms |
47328 KB |
Output is correct |
3 |
Correct |
20 ms |
47452 KB |
Output is correct |
4 |
Correct |
19 ms |
47288 KB |
Output is correct |
5 |
Correct |
19 ms |
47452 KB |
Output is correct |
6 |
Correct |
20 ms |
47452 KB |
Output is correct |
7 |
Correct |
20 ms |
47452 KB |
Output is correct |
8 |
Correct |
21 ms |
47376 KB |
Output is correct |
9 |
Correct |
20 ms |
47452 KB |
Output is correct |
10 |
Correct |
20 ms |
47452 KB |
Output is correct |
11 |
Correct |
20 ms |
47424 KB |
Output is correct |
12 |
Correct |
26 ms |
47352 KB |
Output is correct |
13 |
Correct |
21 ms |
47452 KB |
Output is correct |
14 |
Correct |
21 ms |
47232 KB |
Output is correct |
15 |
Correct |
21 ms |
47452 KB |
Output is correct |
16 |
Correct |
20 ms |
47452 KB |
Output is correct |
17 |
Correct |
22 ms |
47452 KB |
Output is correct |
18 |
Correct |
20 ms |
47448 KB |
Output is correct |
19 |
Correct |
23 ms |
47452 KB |
Output is correct |
20 |
Correct |
22 ms |
47452 KB |
Output is correct |
21 |
Correct |
22 ms |
47296 KB |
Output is correct |
22 |
Correct |
22 ms |
47448 KB |
Output is correct |
23 |
Correct |
23 ms |
47452 KB |
Output is correct |
24 |
Correct |
31 ms |
47400 KB |
Output is correct |
25 |
Correct |
24 ms |
47452 KB |
Output is correct |
26 |
Correct |
23 ms |
47448 KB |
Output is correct |
27 |
Correct |
22 ms |
47452 KB |
Output is correct |
28 |
Correct |
23 ms |
47488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47308 KB |
Output is correct |
2 |
Correct |
25 ms |
47328 KB |
Output is correct |
3 |
Correct |
20 ms |
47452 KB |
Output is correct |
4 |
Correct |
19 ms |
47288 KB |
Output is correct |
5 |
Correct |
19 ms |
47452 KB |
Output is correct |
6 |
Correct |
20 ms |
47452 KB |
Output is correct |
7 |
Correct |
20 ms |
47452 KB |
Output is correct |
8 |
Correct |
21 ms |
47376 KB |
Output is correct |
9 |
Correct |
20 ms |
47452 KB |
Output is correct |
10 |
Correct |
20 ms |
47452 KB |
Output is correct |
11 |
Correct |
20 ms |
47424 KB |
Output is correct |
12 |
Correct |
26 ms |
47352 KB |
Output is correct |
13 |
Correct |
21 ms |
47452 KB |
Output is correct |
14 |
Correct |
21 ms |
47232 KB |
Output is correct |
15 |
Correct |
21 ms |
47452 KB |
Output is correct |
16 |
Correct |
20 ms |
47452 KB |
Output is correct |
17 |
Correct |
22 ms |
47452 KB |
Output is correct |
18 |
Correct |
20 ms |
47448 KB |
Output is correct |
19 |
Correct |
23 ms |
47452 KB |
Output is correct |
20 |
Correct |
22 ms |
47452 KB |
Output is correct |
21 |
Correct |
22 ms |
47296 KB |
Output is correct |
22 |
Correct |
22 ms |
47448 KB |
Output is correct |
23 |
Correct |
23 ms |
47452 KB |
Output is correct |
24 |
Correct |
31 ms |
47400 KB |
Output is correct |
25 |
Correct |
24 ms |
47452 KB |
Output is correct |
26 |
Correct |
23 ms |
47448 KB |
Output is correct |
27 |
Correct |
22 ms |
47452 KB |
Output is correct |
28 |
Correct |
23 ms |
47488 KB |
Output is correct |
29 |
Correct |
122 ms |
47452 KB |
Output is correct |
30 |
Correct |
138 ms |
47476 KB |
Output is correct |
31 |
Correct |
134 ms |
47460 KB |
Output is correct |
32 |
Correct |
100 ms |
47652 KB |
Output is correct |
33 |
Correct |
78 ms |
47452 KB |
Output is correct |
34 |
Correct |
137 ms |
47448 KB |
Output is correct |
35 |
Correct |
163 ms |
47660 KB |
Output is correct |
36 |
Correct |
179 ms |
47676 KB |
Output is correct |
37 |
Correct |
276 ms |
47704 KB |
Output is correct |
38 |
Correct |
314 ms |
47648 KB |
Output is correct |
39 |
Correct |
128 ms |
47652 KB |
Output is correct |
40 |
Correct |
136 ms |
47452 KB |
Output is correct |
41 |
Correct |
131 ms |
47660 KB |
Output is correct |
42 |
Correct |
129 ms |
47448 KB |
Output is correct |
43 |
Correct |
87 ms |
47452 KB |
Output is correct |
44 |
Correct |
106 ms |
47452 KB |
Output is correct |
45 |
Correct |
132 ms |
47660 KB |
Output is correct |
46 |
Correct |
151 ms |
47448 KB |
Output is correct |
47 |
Correct |
137 ms |
47452 KB |
Output is correct |
48 |
Correct |
139 ms |
47664 KB |
Output is correct |
49 |
Correct |
152 ms |
47704 KB |
Output is correct |
50 |
Correct |
180 ms |
47672 KB |
Output is correct |
51 |
Correct |
94 ms |
47448 KB |
Output is correct |
52 |
Correct |
102 ms |
47452 KB |
Output is correct |
53 |
Correct |
117 ms |
47448 KB |
Output is correct |
54 |
Correct |
152 ms |
47664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47308 KB |
Output is correct |
2 |
Correct |
25 ms |
47328 KB |
Output is correct |
3 |
Correct |
132 ms |
67772 KB |
Output is correct |
4 |
Correct |
211 ms |
69604 KB |
Output is correct |
5 |
Correct |
117 ms |
65248 KB |
Output is correct |
6 |
Correct |
121 ms |
66492 KB |
Output is correct |
7 |
Correct |
117 ms |
66020 KB |
Output is correct |
8 |
Correct |
104 ms |
65884 KB |
Output is correct |
9 |
Correct |
125 ms |
66240 KB |
Output is correct |
10 |
Correct |
160 ms |
67148 KB |
Output is correct |
11 |
Correct |
118 ms |
65536 KB |
Output is correct |
12 |
Correct |
135 ms |
67052 KB |
Output is correct |
13 |
Correct |
91 ms |
64960 KB |
Output is correct |
14 |
Correct |
101 ms |
66328 KB |
Output is correct |
15 |
Correct |
131 ms |
67004 KB |
Output is correct |
16 |
Correct |
159 ms |
67512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47308 KB |
Output is correct |
2 |
Correct |
25 ms |
47328 KB |
Output is correct |
3 |
Correct |
20 ms |
47452 KB |
Output is correct |
4 |
Correct |
19 ms |
47288 KB |
Output is correct |
5 |
Correct |
19 ms |
47452 KB |
Output is correct |
6 |
Correct |
20 ms |
47452 KB |
Output is correct |
7 |
Correct |
20 ms |
47452 KB |
Output is correct |
8 |
Correct |
21 ms |
47376 KB |
Output is correct |
9 |
Correct |
20 ms |
47452 KB |
Output is correct |
10 |
Correct |
20 ms |
47452 KB |
Output is correct |
11 |
Correct |
20 ms |
47424 KB |
Output is correct |
12 |
Correct |
26 ms |
47352 KB |
Output is correct |
13 |
Correct |
21 ms |
47452 KB |
Output is correct |
14 |
Correct |
21 ms |
47232 KB |
Output is correct |
15 |
Correct |
21 ms |
47452 KB |
Output is correct |
16 |
Correct |
20 ms |
47452 KB |
Output is correct |
17 |
Correct |
22 ms |
47452 KB |
Output is correct |
18 |
Correct |
20 ms |
47448 KB |
Output is correct |
19 |
Correct |
23 ms |
47452 KB |
Output is correct |
20 |
Correct |
22 ms |
47452 KB |
Output is correct |
21 |
Correct |
22 ms |
47296 KB |
Output is correct |
22 |
Correct |
22 ms |
47448 KB |
Output is correct |
23 |
Correct |
23 ms |
47452 KB |
Output is correct |
24 |
Correct |
31 ms |
47400 KB |
Output is correct |
25 |
Correct |
24 ms |
47452 KB |
Output is correct |
26 |
Correct |
23 ms |
47448 KB |
Output is correct |
27 |
Correct |
22 ms |
47452 KB |
Output is correct |
28 |
Correct |
23 ms |
47488 KB |
Output is correct |
29 |
Correct |
132 ms |
67772 KB |
Output is correct |
30 |
Correct |
211 ms |
69604 KB |
Output is correct |
31 |
Correct |
117 ms |
65248 KB |
Output is correct |
32 |
Correct |
121 ms |
66492 KB |
Output is correct |
33 |
Correct |
117 ms |
66020 KB |
Output is correct |
34 |
Correct |
104 ms |
65884 KB |
Output is correct |
35 |
Correct |
125 ms |
66240 KB |
Output is correct |
36 |
Correct |
160 ms |
67148 KB |
Output is correct |
37 |
Correct |
118 ms |
65536 KB |
Output is correct |
38 |
Correct |
135 ms |
67052 KB |
Output is correct |
39 |
Correct |
91 ms |
64960 KB |
Output is correct |
40 |
Correct |
101 ms |
66328 KB |
Output is correct |
41 |
Correct |
131 ms |
67004 KB |
Output is correct |
42 |
Correct |
159 ms |
67512 KB |
Output is correct |
43 |
Execution timed out |
2068 ms |
69364 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47308 KB |
Output is correct |
2 |
Correct |
25 ms |
47328 KB |
Output is correct |
3 |
Correct |
20 ms |
47452 KB |
Output is correct |
4 |
Correct |
19 ms |
47288 KB |
Output is correct |
5 |
Correct |
19 ms |
47452 KB |
Output is correct |
6 |
Correct |
20 ms |
47452 KB |
Output is correct |
7 |
Correct |
20 ms |
47452 KB |
Output is correct |
8 |
Correct |
21 ms |
47376 KB |
Output is correct |
9 |
Correct |
20 ms |
47452 KB |
Output is correct |
10 |
Correct |
20 ms |
47452 KB |
Output is correct |
11 |
Correct |
20 ms |
47424 KB |
Output is correct |
12 |
Correct |
26 ms |
47352 KB |
Output is correct |
13 |
Correct |
21 ms |
47452 KB |
Output is correct |
14 |
Correct |
21 ms |
47232 KB |
Output is correct |
15 |
Correct |
21 ms |
47452 KB |
Output is correct |
16 |
Correct |
20 ms |
47452 KB |
Output is correct |
17 |
Correct |
22 ms |
47452 KB |
Output is correct |
18 |
Correct |
20 ms |
47448 KB |
Output is correct |
19 |
Correct |
23 ms |
47452 KB |
Output is correct |
20 |
Correct |
22 ms |
47452 KB |
Output is correct |
21 |
Correct |
22 ms |
47296 KB |
Output is correct |
22 |
Correct |
22 ms |
47448 KB |
Output is correct |
23 |
Correct |
23 ms |
47452 KB |
Output is correct |
24 |
Correct |
31 ms |
47400 KB |
Output is correct |
25 |
Correct |
24 ms |
47452 KB |
Output is correct |
26 |
Correct |
23 ms |
47448 KB |
Output is correct |
27 |
Correct |
22 ms |
47452 KB |
Output is correct |
28 |
Correct |
23 ms |
47488 KB |
Output is correct |
29 |
Correct |
122 ms |
47452 KB |
Output is correct |
30 |
Correct |
138 ms |
47476 KB |
Output is correct |
31 |
Correct |
134 ms |
47460 KB |
Output is correct |
32 |
Correct |
100 ms |
47652 KB |
Output is correct |
33 |
Correct |
78 ms |
47452 KB |
Output is correct |
34 |
Correct |
137 ms |
47448 KB |
Output is correct |
35 |
Correct |
163 ms |
47660 KB |
Output is correct |
36 |
Correct |
179 ms |
47676 KB |
Output is correct |
37 |
Correct |
276 ms |
47704 KB |
Output is correct |
38 |
Correct |
314 ms |
47648 KB |
Output is correct |
39 |
Correct |
128 ms |
47652 KB |
Output is correct |
40 |
Correct |
136 ms |
47452 KB |
Output is correct |
41 |
Correct |
131 ms |
47660 KB |
Output is correct |
42 |
Correct |
129 ms |
47448 KB |
Output is correct |
43 |
Correct |
87 ms |
47452 KB |
Output is correct |
44 |
Correct |
106 ms |
47452 KB |
Output is correct |
45 |
Correct |
132 ms |
47660 KB |
Output is correct |
46 |
Correct |
151 ms |
47448 KB |
Output is correct |
47 |
Correct |
137 ms |
47452 KB |
Output is correct |
48 |
Correct |
139 ms |
47664 KB |
Output is correct |
49 |
Correct |
152 ms |
47704 KB |
Output is correct |
50 |
Correct |
180 ms |
47672 KB |
Output is correct |
51 |
Correct |
94 ms |
47448 KB |
Output is correct |
52 |
Correct |
102 ms |
47452 KB |
Output is correct |
53 |
Correct |
117 ms |
47448 KB |
Output is correct |
54 |
Correct |
152 ms |
47664 KB |
Output is correct |
55 |
Execution timed out |
2040 ms |
59472 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47308 KB |
Output is correct |
2 |
Correct |
25 ms |
47328 KB |
Output is correct |
3 |
Correct |
20 ms |
47452 KB |
Output is correct |
4 |
Correct |
19 ms |
47288 KB |
Output is correct |
5 |
Correct |
19 ms |
47452 KB |
Output is correct |
6 |
Correct |
20 ms |
47452 KB |
Output is correct |
7 |
Correct |
20 ms |
47452 KB |
Output is correct |
8 |
Correct |
21 ms |
47376 KB |
Output is correct |
9 |
Correct |
20 ms |
47452 KB |
Output is correct |
10 |
Correct |
20 ms |
47452 KB |
Output is correct |
11 |
Correct |
20 ms |
47424 KB |
Output is correct |
12 |
Correct |
26 ms |
47352 KB |
Output is correct |
13 |
Correct |
21 ms |
47452 KB |
Output is correct |
14 |
Correct |
21 ms |
47232 KB |
Output is correct |
15 |
Correct |
21 ms |
47452 KB |
Output is correct |
16 |
Correct |
20 ms |
47452 KB |
Output is correct |
17 |
Correct |
22 ms |
47452 KB |
Output is correct |
18 |
Correct |
20 ms |
47448 KB |
Output is correct |
19 |
Correct |
23 ms |
47452 KB |
Output is correct |
20 |
Correct |
22 ms |
47452 KB |
Output is correct |
21 |
Correct |
22 ms |
47296 KB |
Output is correct |
22 |
Correct |
22 ms |
47448 KB |
Output is correct |
23 |
Correct |
23 ms |
47452 KB |
Output is correct |
24 |
Correct |
31 ms |
47400 KB |
Output is correct |
25 |
Correct |
24 ms |
47452 KB |
Output is correct |
26 |
Correct |
23 ms |
47448 KB |
Output is correct |
27 |
Correct |
22 ms |
47452 KB |
Output is correct |
28 |
Correct |
23 ms |
47488 KB |
Output is correct |
29 |
Correct |
122 ms |
47452 KB |
Output is correct |
30 |
Correct |
138 ms |
47476 KB |
Output is correct |
31 |
Correct |
134 ms |
47460 KB |
Output is correct |
32 |
Correct |
100 ms |
47652 KB |
Output is correct |
33 |
Correct |
78 ms |
47452 KB |
Output is correct |
34 |
Correct |
137 ms |
47448 KB |
Output is correct |
35 |
Correct |
163 ms |
47660 KB |
Output is correct |
36 |
Correct |
179 ms |
47676 KB |
Output is correct |
37 |
Correct |
276 ms |
47704 KB |
Output is correct |
38 |
Correct |
314 ms |
47648 KB |
Output is correct |
39 |
Correct |
128 ms |
47652 KB |
Output is correct |
40 |
Correct |
136 ms |
47452 KB |
Output is correct |
41 |
Correct |
131 ms |
47660 KB |
Output is correct |
42 |
Correct |
129 ms |
47448 KB |
Output is correct |
43 |
Correct |
87 ms |
47452 KB |
Output is correct |
44 |
Correct |
106 ms |
47452 KB |
Output is correct |
45 |
Correct |
132 ms |
47660 KB |
Output is correct |
46 |
Correct |
151 ms |
47448 KB |
Output is correct |
47 |
Correct |
137 ms |
47452 KB |
Output is correct |
48 |
Correct |
139 ms |
47664 KB |
Output is correct |
49 |
Correct |
152 ms |
47704 KB |
Output is correct |
50 |
Correct |
180 ms |
47672 KB |
Output is correct |
51 |
Correct |
94 ms |
47448 KB |
Output is correct |
52 |
Correct |
102 ms |
47452 KB |
Output is correct |
53 |
Correct |
117 ms |
47448 KB |
Output is correct |
54 |
Correct |
152 ms |
47664 KB |
Output is correct |
55 |
Correct |
132 ms |
67772 KB |
Output is correct |
56 |
Correct |
211 ms |
69604 KB |
Output is correct |
57 |
Correct |
117 ms |
65248 KB |
Output is correct |
58 |
Correct |
121 ms |
66492 KB |
Output is correct |
59 |
Correct |
117 ms |
66020 KB |
Output is correct |
60 |
Correct |
104 ms |
65884 KB |
Output is correct |
61 |
Correct |
125 ms |
66240 KB |
Output is correct |
62 |
Correct |
160 ms |
67148 KB |
Output is correct |
63 |
Correct |
118 ms |
65536 KB |
Output is correct |
64 |
Correct |
135 ms |
67052 KB |
Output is correct |
65 |
Correct |
91 ms |
64960 KB |
Output is correct |
66 |
Correct |
101 ms |
66328 KB |
Output is correct |
67 |
Correct |
131 ms |
67004 KB |
Output is correct |
68 |
Correct |
159 ms |
67512 KB |
Output is correct |
69 |
Execution timed out |
2068 ms |
69364 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |