#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];
int L[205];
bool merge(int a,int b){
int ra=a;
int rb=b;
a=rep[a];
b=rep[b];
// cout<<ra<<' '<<rb<<endl;
if(a==b){
if(dep[ra]==dep[rb])
return 0;
return 1;
}
if(com[a].size()>com[b].size()){
swap(a,b);
swap(ra,rb);
}
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;
vector<pair<int,int>> edge;
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
if(a>b)
swap(a,b);
edge.push_back({a,b});
}
for(int i=0;i<min(205,m+1);i++){
for(int t=0;t<=n;t++){
com[t].clear();
rep[t]=t;
com[t].push_back(t);
}
for(int ii=0;ii<i;ii++){
if(merge(edge[ii].first,edge[ii].second)==0){
L[i]=m+1;
break;
}
}
if(L[i]==m+1)
continue;
for(int j=m-1;j>=i;j--){
if(merge(edge[j].first,edge[j].second)==0){
L[i]=j+1;
break;
}
}
}
// for(int i=0;i<=m;i++){
// cout<<L[i]<<endl;
// }
for(int i=0;i<q;i++){
int l,r;
cin>>l>>r;
if(r<L[l])
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 |
Correct |
3 ms |
10588 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
6 |
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 |
Correct |
3 ms |
10588 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
6 |
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 |
Correct |
1139 ms |
17656 KB |
Output is correct |
4 |
Execution timed out |
2054 ms |
20416 KB |
Time limit exceeded |
5 |
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 |
Correct |
3 ms |
10588 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
6 |
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 |
Correct |
3 ms |
10588 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
6 |
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 |
Correct |
3 ms |
10588 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Incorrect |
3 ms |
10588 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |