Submission #930583

# Submission time Handle Problem Language Result Execution time Memory
930583 2024-02-20T07:19:42 Z UmairAhmadMirza Joker (BOI20_joker) C++17
0 / 100
399 ms 17000 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);
  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;node>=1;node--){
      // cout<<"Include := "<<node<<endl;
      bool brk=0;
      for(auto i:adj[node]){
        if(merge(i,node)==0){
          k=node;
          brk=1;
          break;
        }
        // for(int i=1;i<=n;i++)
        //   cout<<dep[i]<<' ';
        // cout<<endl;
      }
      if(brk)
        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 4 ms 10584 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Incorrect 4 ms 10588 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10584 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Incorrect 4 ms 10588 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10584 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Incorrect 399 ms 17000 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10584 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Incorrect 4 ms 10588 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10584 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Incorrect 4 ms 10588 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10584 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Incorrect 4 ms 10588 KB Output isn't correct
4 Halted 0 ms 0 KB -