#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 p[x] = {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;
ll ho = 199;
if(n<=5000&&q<=5000&&m<=5000) ho = 5000;
for(int i = 1; i <= m ; i++) cin >> a[i].F >> a[i].S;
for(int j = 0; j <= min(m,ho); 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 |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 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 |
4696 KB |
Output is correct |
14 |
Correct |
2 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4560 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
2 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4568 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
2 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4576 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 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 |
4440 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 |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 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 |
4696 KB |
Output is correct |
14 |
Correct |
2 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4560 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
2 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4568 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
2 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4576 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 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 |
4440 KB |
Output is correct |
29 |
Incorrect |
5 ms |
4444 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 |
377 ms |
13948 KB |
Output is correct |
4 |
Correct |
871 ms |
13408 KB |
Output is correct |
5 |
Correct |
135 ms |
13652 KB |
Output is correct |
6 |
Correct |
118 ms |
13696 KB |
Output is correct |
7 |
Correct |
125 ms |
13692 KB |
Output is correct |
8 |
Correct |
238 ms |
11400 KB |
Output is correct |
9 |
Correct |
252 ms |
13704 KB |
Output is correct |
10 |
Correct |
429 ms |
13648 KB |
Output is correct |
11 |
Correct |
435 ms |
13692 KB |
Output is correct |
12 |
Correct |
400 ms |
13696 KB |
Output is correct |
13 |
Correct |
270 ms |
11756 KB |
Output is correct |
14 |
Correct |
241 ms |
11644 KB |
Output is correct |
15 |
Correct |
381 ms |
13908 KB |
Output is correct |
16 |
Correct |
439 ms |
13692 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 |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 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 |
4696 KB |
Output is correct |
14 |
Correct |
2 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4560 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
2 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4568 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
2 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4576 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 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 |
4440 KB |
Output is correct |
29 |
Correct |
377 ms |
13948 KB |
Output is correct |
30 |
Correct |
871 ms |
13408 KB |
Output is correct |
31 |
Correct |
135 ms |
13652 KB |
Output is correct |
32 |
Correct |
118 ms |
13696 KB |
Output is correct |
33 |
Correct |
125 ms |
13692 KB |
Output is correct |
34 |
Correct |
238 ms |
11400 KB |
Output is correct |
35 |
Correct |
252 ms |
13704 KB |
Output is correct |
36 |
Correct |
429 ms |
13648 KB |
Output is correct |
37 |
Correct |
435 ms |
13692 KB |
Output is correct |
38 |
Correct |
400 ms |
13696 KB |
Output is correct |
39 |
Correct |
270 ms |
11756 KB |
Output is correct |
40 |
Correct |
241 ms |
11644 KB |
Output is correct |
41 |
Correct |
381 ms |
13908 KB |
Output is correct |
42 |
Correct |
439 ms |
13692 KB |
Output is correct |
43 |
Correct |
368 ms |
13764 KB |
Output is correct |
44 |
Correct |
869 ms |
13952 KB |
Output is correct |
45 |
Correct |
795 ms |
13932 KB |
Output is correct |
46 |
Correct |
101 ms |
13652 KB |
Output is correct |
47 |
Correct |
105 ms |
13696 KB |
Output is correct |
48 |
Correct |
286 ms |
13652 KB |
Output is correct |
49 |
Correct |
473 ms |
13948 KB |
Output is correct |
50 |
Correct |
505 ms |
11804 KB |
Output is correct |
51 |
Correct |
440 ms |
14096 KB |
Output is correct |
52 |
Correct |
395 ms |
14068 KB |
Output is correct |
53 |
Correct |
230 ms |
11600 KB |
Output is correct |
54 |
Correct |
275 ms |
11604 KB |
Output is correct |
55 |
Correct |
390 ms |
13880 KB |
Output is correct |
56 |
Correct |
467 ms |
13904 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 |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 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 |
4696 KB |
Output is correct |
14 |
Correct |
2 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4560 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
2 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4568 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
2 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4576 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 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 |
4440 KB |
Output is correct |
29 |
Incorrect |
5 ms |
4444 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 |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 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 |
4696 KB |
Output is correct |
14 |
Correct |
2 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4560 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
2 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4568 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
2 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4576 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 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 |
4440 KB |
Output is correct |
29 |
Incorrect |
5 ms |
4444 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |