Submission #930592

# Submission time Handle Problem Language Result Execution time Memory
930592 2024-02-20T07:35:00 Z UmairAhmadMirza Joker (BOI20_joker) C++17
0 / 100
2000 ms 118288 KB
#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<<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});
    }
    // cout<<k<<endl;
    for(int i=0;i<q;i++){
      for(int i=1;i<=n;i++){
        rep[i]=i;
        com[i].clear();
        com[i].push_back(i);
      }
      int l,r;
      cin>>l>>r;
      string ans="NO";
      for(int i=0;i<m;i++){
        if(l<=i && i<=r)
          continue;
        if(merge(edge[i].first,edge[i].second)==0){
          ans="YES";
          break;
        }
      }
      cout<<ans<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10588 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Incorrect 3 ms 10812 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10588 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Incorrect 3 ms 10812 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10588 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Execution timed out 2037 ms 118288 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10588 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Incorrect 3 ms 10812 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10588 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Incorrect 3 ms 10812 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10588 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Incorrect 3 ms 10812 KB Output isn't correct
4 Halted 0 ms 0 KB -