Submission #704585

#TimeUsernameProblemLanguageResultExecution timeMemory
704585bin9638ICC (CEOI16_icc)C++17
100 / 100
132 ms508 KiB
#ifndef SKY #include<icc.h> #endif // SKY #include <bits/stdc++.h> using namespace std; #define ll long long #define fs first #define sc second #define N 110 #define pb push_back struct DSU { int lab[N]; void init(int n) { memset(lab,-1,sizeof(lab)); } int root(int u) { if(lab[u]<0) return u; return(lab[u]=root(lab[u])); } void update(int u,int v) { if((u=root(u))==(v=root(v))) return; if(lab[u]>lab[v]) swap(u,v); lab[u]+=lab[v]; lab[v]=u; } }T; int edge[N][N]; #ifdef SKY void setRoad(int u, int v) { cout<<u<<" "<<v<<endl; } int query(int size_a,int size_b,int a[],int b[]) { for(int i=0;i<size_a;i++) for(int j=0;j<size_b;j++) if(edge[a[i]][b[j]]==1) return 1; return 0; } #endif // SKY int make_query(vector<int>L,vector<int>R) { int a[N]={},b[N]={}; for(int i=0;i<L.size();i++) a[i]=L[i]; for(int i=0;i<R.size();i++) b[i]=R[i]; return query(L.size(),R.size(),a,b); } void chia_tap(vector<int>&L,vector<int>R) { vector<int>luu; int sz=L.size(); for(int i=1;i*2<=sz;i++) { luu.pb(L.back()); L.pop_back(); } if(make_query(L,R)==0) L=luu; } void solve(int n) { #ifdef SKY int u,v; cin>>u>>v; // cout<<u<<" "<<v<<endl; edge[u][v]=edge[v][u]=1; #endif // SKY int dem=0; vector<int>lis[N],L,R; for(int i=1;i<=n;i++) if(T.root(i)==i) { dem++; for(int j=1;j<=n;j++) if(T.root(j)==i) lis[dem].pb(j); } //cout<<dem<<endl; for(int i=0;(1<<i)<=dem;i++) { L.clear(); R.clear(); for(int j=1;j<=dem;j++) if((j>>i)&1) { for(auto u:lis[j]) L.pb(u); }else { for(auto u:lis[j]) R.pb(u); } // cout<<i<<" "<<L.size()<<" "<<R.size()<<" "<<make_query(L,R)<<endl; if(make_query(L,R)) break; } while(L.size()>1) chia_tap(L,R); swap(L,R); while(L.size()>1) chia_tap(L,R); setRoad(L[0],R[0]); T.update(L[0],R[0]); } void run(int cc) { T.init(cc); for(int i=1;i<cc;i++) solve(cc); } #ifdef SKY int main() { freopen("A.inp","r",stdin); freopen("A.out","w",stdout); int n; cin>>n; run(n); return 0; } #endif // SKY

Compilation message (stderr)

icc.cpp: In function 'int make_query(std::vector<int>, std::vector<int>)':
icc.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i=0;i<L.size();i++)
      |                 ~^~~~~~~~~
icc.cpp:64:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for(int i=0;i<R.size();i++)
      |                 ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...