#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
const int N=2e5+4;
vector<int> root(N), dist(N);
int find(int x){
if(x==root[x])return x;
return find(root[x]);
}
int cnt(int x){
if(x==root[x])return dist[x];
return dist[x] + cnt(root[x]);
}
bool unify(int x, int y){
int a=find(x);
int b=find(y);
int c1=cnt(x), c2=cnt(y);
if(a==b && c1%2==c2%2){
return true;
}
if(a!=b){
root[b]=a;
dist[b]=1;
}
return false;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,m,q;
cin>>n>>m>>q;
vector<pi> edge;
for(int j=0; j<m; j++){
int u,v;
cin>>u>>v;
edge.push_back({u,v});
}for(int j=1; j<=n; j++){
root[j]=j;
}for(int j=0; j<q; j++){
int l,r;
cin>>l>>r;
l--;
r--;
for(int i=1; i<=n; i++)root[j]=j;
string ans="NO";
for(int i=0; i<l; i++){
auto p=edge[i];
if(unify(p.first, p.second)){
ans="YES";
}
}for(int i=r+1; i<m; i++){
auto p=edge[i];
if(unify(p.first, p.second)){
ans="YES";
}
}cout<<ans<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3408 KB |
Output is correct |
2 |
Correct |
3 ms |
3584 KB |
Output is correct |
3 |
Correct |
3 ms |
3664 KB |
Output is correct |
4 |
Correct |
3 ms |
3576 KB |
Output is correct |
5 |
Correct |
3 ms |
3408 KB |
Output is correct |
6 |
Incorrect |
4 ms |
3408 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3408 KB |
Output is correct |
2 |
Correct |
3 ms |
3584 KB |
Output is correct |
3 |
Correct |
3 ms |
3664 KB |
Output is correct |
4 |
Correct |
3 ms |
3576 KB |
Output is correct |
5 |
Correct |
3 ms |
3408 KB |
Output is correct |
6 |
Incorrect |
4 ms |
3408 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3408 KB |
Output is correct |
2 |
Correct |
3 ms |
3584 KB |
Output is correct |
3 |
Execution timed out |
2045 ms |
11456 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3408 KB |
Output is correct |
2 |
Correct |
3 ms |
3584 KB |
Output is correct |
3 |
Correct |
3 ms |
3664 KB |
Output is correct |
4 |
Correct |
3 ms |
3576 KB |
Output is correct |
5 |
Correct |
3 ms |
3408 KB |
Output is correct |
6 |
Incorrect |
4 ms |
3408 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3408 KB |
Output is correct |
2 |
Correct |
3 ms |
3584 KB |
Output is correct |
3 |
Correct |
3 ms |
3664 KB |
Output is correct |
4 |
Correct |
3 ms |
3576 KB |
Output is correct |
5 |
Correct |
3 ms |
3408 KB |
Output is correct |
6 |
Incorrect |
4 ms |
3408 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3408 KB |
Output is correct |
2 |
Correct |
3 ms |
3584 KB |
Output is correct |
3 |
Correct |
3 ms |
3664 KB |
Output is correct |
4 |
Correct |
3 ms |
3576 KB |
Output is correct |
5 |
Correct |
3 ms |
3408 KB |
Output is correct |
6 |
Incorrect |
4 ms |
3408 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |