Submission #871606

# Submission time Handle Problem Language Result Execution time Memory
871606 2023-11-11T07:37:05 Z Faisal_Saqib ICC (CEOI16_icc) C++17
61 / 100
128 ms 644 KB
#include "icc.h"
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define vll vector<int>
#define all(a) (a).begin(), (a).end()
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());  
#define NEX(v) shuffle(all(v), RNG); 
const int N=200;
int par[N];
int sz[N];
// bool ka[N][N];
// void setRoad(int x,int y)
// {

// }
// int query(int n,int m,int a[],int b[])
// {
//   // cout<<"Why? asking \n";
//   // for(int i=0;i<n;i++)
//   // {
//   //   cout<<a[i]<<' ';
//   // }
//   // cout<<endl;
//   // for(int j=0;j<m;j++)
//   // {
//   //   cout<<b[j]<<' ';
//   // }
//   // cout<<endl;
//   for(int i=0;i<n;i++)
//   {
//     for(int j=0;j<m;j++)
//     {
//       if(ka[a[i]][b[j]])
//         return 1;
//     }
//   }
//   return 0;
// }
void init(int n)
{
    for(int i=1;i<=n;i++)
    {
        par[i]=i;
        sz[i]=1;
    }
}
int root(int x)
{
    return (par[x]==x?x:par[x]=root(par[x]));
}
void join(int x,int y)
{
    x=root(x);
    y=root(y);
    if(x!=y)
    {
        par[x]=y;
        sz[y]+=sz[x];
    }
}
int n_n_n;
vll modify(vll& a)
{
  vll b;
  for(auto i:a)
    for(int j=1;j<=n_n_n;j++)
      if(root(j)==i)
        b.push_back(j);
  return b;
}
int check_edge(vll& a,vll& b)
{
  int n=a.size();
  int m=b.size();
  int a_[n];
  for(int i=0;i<n;i++)
    a_[i]=a[i];
  int b_[m];
  for(int i=0;i<m;i++)
    b_[i]=b[i];
  return query(n,m,a_,b_);
}
vll fit,sed;
int fix_first(int l,int r)
{
  if(l==r)
    return l;
  int mid=(l+r)/2;
  vll cur;
  for(int i=l;i<=mid;i++)
    cur.push_back(fit[i]);
  if(check_edge(cur,sed))
    return fix_first(l,mid);
  else
    return fix_first(mid+1,r);
}
void between(vll& a,vll& b)
{
  fit=a;
  sed=b;
  int ind=fix_first(0,((int)a.size())-1);
  // cout<<"Hello "<<' '<<ind<<' '<<a[ind]<<endl;
  fit={fit[ind]};
  swap(sed,fit);
  ind=fix_first(0,((int)b.size())-1);
  // cout<<"Hello "<<' '<<ind<<' '<<b[ind]<<endl;
  fit={fit[ind]};
}
bool found_=0;
void solve(vll& big)
{
  if(big.size()==1)
  {
    return;
  }
  while(1){
      vll a,b;
      int n_=big.size();
      for(int i=0;i<(n_/2);i++)
        a.push_back(big[i]);
      for(int j=(n_/2);j<n_;j++)
        b.push_back(big[j]);
      vll c=modify(a),d=modify(b);
      if(check_edge(c,d))
      {
        between(c,d);
        found_=1;
        break;
      }
      NEX(big);
  }
}
void run(int n)
{
  n_n_n=n;
  init(n);
  int q=n-1;
  while(q--)
  {
    // cout<<"Add edge \n";
    // int x_,y_;
    // cin>>x_>>y_;
    // ka[x_][y_]=1;
    // ka[y_][x_]=1;
    vll big;
    for(int i=1;i<=n;i++)
      if(par[i]==i)
        big.push_back(i);
    // for(auto i:big)
    // {
    //   cout<<i<<' ';
    // }
    // cout<<endl;
    // cout<<"HEllo "<<check_edge(a,b)<<endl;;
    found_=0;
    solve(big);
    // cout<<"edge is "<<fit[0]<<' '<<sed[0]<<endl;
    join(fit[0],sed[0]);
    setRoad(fit[0],sed[0]);
    // break;
  }
}
// int main()
// {
//   int n;
//   cin>>n;  
//   run(n);
// }
# Verdict Execution time Memory Grader output
1 Correct 4 ms 604 KB Ok! 99 queries used.
2 Correct 4 ms 604 KB Ok! 106 queries used.
# Verdict Execution time Memory Grader output
1 Correct 30 ms 604 KB Ok! 539 queries used.
2 Correct 34 ms 604 KB Ok! 814 queries used.
3 Correct 35 ms 604 KB Ok! 811 queries used.
# Verdict Execution time Memory Grader output
1 Correct 84 ms 604 KB Ok! 1488 queries used.
2 Correct 128 ms 620 KB Ok! 2132 queries used.
3 Correct 99 ms 604 KB Ok! 1734 queries used.
4 Correct 95 ms 632 KB Ok! 1674 queries used.
# Verdict Execution time Memory Grader output
1 Correct 88 ms 632 KB Ok! 1572 queries used.
2 Correct 92 ms 604 KB Ok! 1556 queries used.
3 Correct 105 ms 644 KB Ok! 1835 queries used.
4 Correct 92 ms 644 KB Ok! 1630 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 109 ms 600 KB Too many queries! 1864 out of 1775
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 121 ms 620 KB Too many queries! 1918 out of 1625
2 Halted 0 ms 0 KB -