#include <bits/stdc++.h>
using namespace std;
int const N=2e5+5;
vector<int> adj[N];
bool dep[N];
int rep[N];
vector<int> com[N];
// int dp[N][N];
bool merge(int a,int b){
int ra=a;
int rb=b;
a=rep[a];
b=rep[b];
// cout<<a<<' '<<b<<endl;
if(a==b){
if(dep[ra]==dep[rb])
return 0;
return 1;
}
if(com[a].size()>com[b].size())
swap(a,b);
bool sw=0;
if(dep[ra]==dep[rb])
sw=1;
for(auto i:com[a]){
com[b].push_back(i);
rep[i]=b;
dep[i]^=sw;
}
com[a].clear();
return 1;
}
int main()
{
int n,m,q;
cin>>n>>m>>q;
for(int i=1;i<=n;i++){
com[i].push_back(i);
rep[i]=i;
}
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
if(a>b)
swap(a,b);
adj[a].push_back(b);
}
int k=0;
for(int node=n-1;node>=1;node--){
for(auto i:adj[node]){
if(merge(i,node)==0){
k=node;
break;
}
}
}
// cout<<k<<endl;
for(int i=0;i<q;i++){
int l,r;
cin>>l>>r;
if(r<=k)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10588 KB |
Output is correct |
2 |
Correct |
3 ms |
10588 KB |
Output is correct |
3 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10588 KB |
Output is correct |
2 |
Correct |
3 ms |
10588 KB |
Output is correct |
3 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10588 KB |
Output is correct |
2 |
Correct |
3 ms |
10588 KB |
Output is correct |
3 |
Incorrect |
402 ms |
20004 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10588 KB |
Output is correct |
2 |
Correct |
3 ms |
10588 KB |
Output is correct |
3 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10588 KB |
Output is correct |
2 |
Correct |
3 ms |
10588 KB |
Output is correct |
3 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10588 KB |
Output is correct |
2 |
Correct |
3 ms |
10588 KB |
Output is correct |
3 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |