# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
871546 |
2023-11-11T05:24:35 Z |
Faisal_Saqib |
ICC (CEOI16_icc) |
C++17 |
|
303 ms |
628 KB |
#include "icc.h"
#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define vll vector<int>
const int N=200;
int par[N];
int sz[N];
// bool adj[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(adj[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)
{
swap(x,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_);
}
int check_edge1(vll& c,vll& d)
{
vll a=modify(c),b=modify(d);
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)
{
a=modify(a);
b=modify(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]};
}
void run(int n)
{
n_n_n=n;
init(n);
int q=n-1;
while(q--)
{
// int x_,y_;
// cin>>x_>>y_;
// cout<<"New edge is "<<x_<<' '<<y_<<endl;
// adj[x_][y_]=adj[y_][x_]=1;
vll shif;
shif.push_back(0);
for(int i=1;i<=n;i++)
if(root(i)==i)
shif.push_back(i);
int e;
for(int mid=2;mid<shif.size();mid++){
vll big;
for(int i=1;i<mid;i++)
big.push_back(shif[i]);
vll pk;
for(int i=mid;i<shif.size();i++)
pk.push_back(shif[i]);
if(check_edge1(big,pk))
{
e=mid;
break;
}
}
// cout<<"Hello "<<e<<endl;
// for(int i=0;i<shif.size();i++)
// {
// cout<<i<<' '<<shif[i]<<endl;;
// }
vll big;
for(int j=1;j<e;j++)
big.push_back(shif[j]);
vll pk;
for(int j=e;j<shif.size();j++)
pk.push_back(shif[j]);
// cout<<"Big :";
// for(auto i:big)
// {
// cout<<i<<' ';
// }
// cout<<endl;
// cout<<"pk :";
// for(auto i:pk)
// {
// cout<<i<<' ';
// }
// cout<<endl;
between(big,pk);
// cout<<"Big :";
// for(auto i:big)
// {
// cout<<i<<' ';
// }
// cout<<endl;
// cout<<"pk :";
// for(auto i:pk)
// {
// cout<<i<<' ';
// }
// cout<<endl;
// 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);
// }
Compilation message
icc.cpp: In function 'void run(int)':
icc.cpp:142:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
142 | for(int mid=2;mid<shif.size();mid++){
| ~~~^~~~~~~~~~~~
icc.cpp:147:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
147 | for(int i=mid;i<shif.size();i++)
| ~^~~~~~~~~~~~
icc.cpp:164:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
164 | for(int j=e;j<shif.size();j++)
| ~^~~~~~~~~~~~
icc.cpp:164:17: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
164 | for(int j=e;j<shif.size();j++)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
600 KB |
Ok! 167 queries used. |
2 |
Correct |
5 ms |
604 KB |
Ok! 150 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
604 KB |
Ok! 1529 queries used. |
2 |
Correct |
67 ms |
612 KB |
Ok! 1592 queries used. |
3 |
Correct |
67 ms |
600 KB |
Ok! 1617 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
303 ms |
628 KB |
Number of queries more than 4500 out of 2250 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
277 ms |
616 KB |
Number of queries more than 4000 out of 2000 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
252 ms |
608 KB |
Number of queries more than 3550 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
235 ms |
600 KB |
Number of queries more than 3250 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |