#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define S second
#define F first
#define all(x) (x).begin(),(x).end()
#define sz size()
#define Yes cout << "YES" << endl
#define No cout << "NO" << endl
#define pb(x) push_back(x);
#define endl '\n'
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N=3e5+7;
ll INF=INT_MAX,mod=1e9+7;
int TT=1;
ll power(ll x, unsigned int y)
{
ll res = 1;
x = x; // % mod;
if (x == 0) return 0;
while (y > 0)
{
if (y & 1) res = (res*x) ; // % mod;
y = y>>1;
x = (x*x) ; // % mod;
}
return res;
}
pair<ll,ll> p[N];
ll siz[N];
pair<ll,ll> get(ll x)
{
if(p[x].F==x) return p[x];
pair<ll,ll> hi = get(p[x].F);
return {hi.F,hi.S^p[x].S};
}
pair<ll,ll> a[N];
ll ans[201];
void solve()
{
ll n , m, q; cin >> n >> m >> q;
ll lst = 0;
for(int i = 1; i <= m ; i++) cin >> a[i].F >> a[i].S;
for(int j = 0; j <= min(m,199LL); j++){
for(int i = 1; i <= n; i++) siz[i] = 1,p[i] = {i,0};
lst = 0;
for(int i = 1; i <= j; i++)
{
ll x = a[i].F , y = a[i].S;
pair<ll,ll> paix = get(x);
pair<ll,ll> paiy = get(y);
ll xx = paix.F, yy = paiy.F;
// cout << xx << " " << yy << endl;
if(xx!=yy)
{
bool b = (paix.S==paiy.S);
if(siz[xx]<siz[yy])
{
p[xx] = {yy,b};
siz[yy]+=siz[xx];
}
else
{
p[yy] = {xx,b};
siz[xx]+=siz[yy];
}
}
else
{
if(paix.S==paiy.S&&lst==0) {lst = i; break;}
}
}
if(lst!=0) {ans[j] = m+1; continue;}
lst = 0;
for(int i = m; i >j; i--)
{
ll x = a[i].F , y = a[i].S;
pair<ll,ll> paix = get(x);
pair<ll,ll> paiy = get(y);
ll xx = paix.F, yy = paiy.F;
// cout << xx << " " << yy << endl;
if(xx!=yy)
{
bool b = (paix.S==paiy.S);
if(siz[xx]<siz[yy])
{
p[xx] = {yy,b};
siz[yy]+=siz[xx];
}
else
{
p[yy] = {xx,b};
siz[xx]+=siz[yy];
}
}
else
{
if(paix.S==paiy.S&&lst==0) {lst = i; break;}
}
}
ans[j] = lst;
}
while(q--)
{
ll l, r; cin >> l >> r;
if(r<ans[l-1]) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
int main(){
//freopen("friday.in","r",stdin);
//freopen("friday.out","w",stdout);
fast;
//cin >> TT;
while(TT--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Incorrect |
3 ms |
4440 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
292 ms |
11404 KB |
Output is correct |
4 |
Correct |
721 ms |
11392 KB |
Output is correct |
5 |
Correct |
127 ms |
11348 KB |
Output is correct |
6 |
Correct |
116 ms |
11392 KB |
Output is correct |
7 |
Correct |
110 ms |
11392 KB |
Output is correct |
8 |
Correct |
210 ms |
9556 KB |
Output is correct |
9 |
Correct |
210 ms |
11860 KB |
Output is correct |
10 |
Correct |
363 ms |
11648 KB |
Output is correct |
11 |
Correct |
384 ms |
11608 KB |
Output is correct |
12 |
Correct |
349 ms |
11348 KB |
Output is correct |
13 |
Correct |
433 ms |
9340 KB |
Output is correct |
14 |
Correct |
218 ms |
9300 KB |
Output is correct |
15 |
Correct |
326 ms |
11392 KB |
Output is correct |
16 |
Correct |
375 ms |
11392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
292 ms |
11404 KB |
Output is correct |
30 |
Correct |
721 ms |
11392 KB |
Output is correct |
31 |
Correct |
127 ms |
11348 KB |
Output is correct |
32 |
Correct |
116 ms |
11392 KB |
Output is correct |
33 |
Correct |
110 ms |
11392 KB |
Output is correct |
34 |
Correct |
210 ms |
9556 KB |
Output is correct |
35 |
Correct |
210 ms |
11860 KB |
Output is correct |
36 |
Correct |
363 ms |
11648 KB |
Output is correct |
37 |
Correct |
384 ms |
11608 KB |
Output is correct |
38 |
Correct |
349 ms |
11348 KB |
Output is correct |
39 |
Correct |
433 ms |
9340 KB |
Output is correct |
40 |
Correct |
218 ms |
9300 KB |
Output is correct |
41 |
Correct |
326 ms |
11392 KB |
Output is correct |
42 |
Correct |
375 ms |
11392 KB |
Output is correct |
43 |
Correct |
288 ms |
11600 KB |
Output is correct |
44 |
Correct |
706 ms |
15348 KB |
Output is correct |
45 |
Correct |
644 ms |
15956 KB |
Output is correct |
46 |
Correct |
93 ms |
15656 KB |
Output is correct |
47 |
Correct |
114 ms |
15696 KB |
Output is correct |
48 |
Correct |
254 ms |
15700 KB |
Output is correct |
49 |
Correct |
415 ms |
15600 KB |
Output is correct |
50 |
Correct |
464 ms |
13680 KB |
Output is correct |
51 |
Correct |
385 ms |
15856 KB |
Output is correct |
52 |
Correct |
372 ms |
15856 KB |
Output is correct |
53 |
Correct |
337 ms |
13420 KB |
Output is correct |
54 |
Correct |
245 ms |
13552 KB |
Output is correct |
55 |
Correct |
321 ms |
15860 KB |
Output is correct |
56 |
Correct |
404 ms |
16104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Incorrect |
3 ms |
4440 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Incorrect |
3 ms |
4440 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |