# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
871492 |
2023-11-11T03:53:00 Z |
Faisal_Saqib |
ICC (CEOI16_icc) |
C++17 |
|
246 ms |
856 KB |
#include "icc.h"
#include <iostream>
#include <vector>
using namespace std;
#define vll vector<int>
const int N=200;
int par[N];
int sz[N];
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);
fit={fit[ind]};
swap(sed,fit);
ind=fix_first(0,((int)b.size())-1);
fit={fit[ind]};
}
bool found_=0;
void solve(vll& big)
{
if(big.size()==1)
return;
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;
}
else
{
solve(b);
if(!found_)
solve(a);
}
}
void run(int n)
{
n_n_n=n;
init(n);
int q=n-1;
while(q--)
{
vll big;
for(int i=1;i<=n;i++)
if(par[i]==i)
big.push_back(i);
found_=0;
solve(big);
join(fit[0],sed[0]);
setRoad(fit[0],sed[0]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
604 KB |
Ok! 95 queries used. |
2 |
Correct |
5 ms |
604 KB |
Ok! 122 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
608 KB |
Ok! 987 queries used. |
2 |
Correct |
67 ms |
844 KB |
Ok! 1397 queries used. |
3 |
Correct |
63 ms |
620 KB |
Ok! 1424 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
246 ms |
620 KB |
Number of queries more than 4500 out of 2250 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
221 ms |
856 KB |
Number of queries more than 4000 out of 2000 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
192 ms |
856 KB |
Number of queries more than 3550 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
175 ms |
604 KB |
Number of queries more than 3250 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |