#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int , int> pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 2e5;
const ll mod = 1e9+7;
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
int n, m, q;
int a[maxn], b[maxn], l[maxn], r[maxn];
int par[maxn];
bool val[maxn];
int getpar(int v){
return ((~par[v]) ? par[v] = getpar(par[v]) : v);
}
bool merge(int v, int u){
int pu = getpar(u) , pv = getpar(v);
if(pu == pv)
return val[u] == val[v];
val[pu] ^= val[v] == val[u];
par[pv] = pu;
return 0;
}
bool solve(int l , int r){
for(int i = 0 ; i < l ; i ++){
if(merge(a[i], b[i])){
if(i > n){
for(int j = 0 ; j < n ; j ++)
par[j] = -1, val[j] = 0;
}
else{
for(int j = 0; j <= i ; j ++)
par[a[j]] = par[b[j]] = -1 , val[a[j]] = val[b[j]] = 0;
}
return 1;
}
}
for(int i = r ; i < m ; i ++){
if(merge(a[i], b[i])){
if(l + i - r > n){
for(int j = 0 ; j < n ; j ++)
par[j] = -1, val[j] = 0;
}
else{
for(int j = 0; j < l ; j ++)
par[a[j]] = par[b[j]] = -1 , val[a[j]] = val[b[j]] = 0;
for(int j = r ; j <= i ; j ++)
par[a[j]] = par[b[j]] = -1 , val[a[j]] = val[b[j]] = 0;
}
return 1;
}
}
return 0;
}
int32_t main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin >> n >> m >> q;
ms(par, -1);
for(int i = 0 ; i < m ; i ++)
cin >> a[i] >> b[i] , a[i] -- , b[i] --;
for(int i = 0 ; i < q ; i ++)
cin >> l[i] >> r[i], l[i] --;
for(int i = 0 ; i < q ; i ++)
cout << (solve(l[i] , r[i]) ? "YES" : "NO") << endl;
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Execution timed out |
2087 ms |
4556 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |