제출 #94393

#제출 시각아이디문제언어결과실행 시간메모리
94393gumballNetwork (BOI15_net)C++14
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; ll n,m,i,ta,tb,D[101010],daun,bes[101010],ROOT,j,P[101010],sudah[101010],sisa; vector<ll> v[101010],C,w[101010]; vector<pair<pair<ll,ll> ,ll> > Z; void dfs(ll aa,ll bb) { //cout<<aa<<" "<<bb<<" "<<cc<<"\n"; bes[aa]=0; if(D[aa]==1)bes[aa]=1; ll ii; for(ii=0;ii<v[aa].size();ii++) if(v[aa][ii]!=bb) { P[v[aa][ii]]=aa; dfs(v[aa][ii],aa); bes[aa]+=bes[v[aa][ii]]; } } void dfs2(ll aa,ll bb,ll cc,ll dd) { if(D[aa]==1) { kel[dd]++; isi[dd].pb(aa); Z.pb(mp(mp(cc,dd),aa)); } ll ii; for(ii=0;ii<v[aa].size();ii++) if(v[aa][ii]!=bb) dfs2(v[aa][ii],aa,cc,dd); } int main() { ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL); cin>>n; for(i=1;i<n;i++) { cin>>ta>>tb; v[ta].pb(tb); v[tb].pb(ta); D[ta]++; D[tb]++; } for(i=1;i<=n;i++) if(D[i]>1) C.pb(i); else daun++; //cout<<daun<<"\n"; for(i=0;i<C.size();i++) { vector<ll> X; ROOT=C[i]; //cout<<ROOT<<"\n"; dfs(ROOT,ROOT); for(j=0;j<v[ROOT].size();j++) X.pb(bes[v[ROOT][j]]); //return 0; sort(X.begin(),X.end()); reverse(X.begin(),X.end()); if(X[0]*2<=daun) break; else ROOT=-1; } if(ROOT==-1)while(1); //cout<<ROOT<<"\n"; //return 0; for(i=0;i<v[ROOT].size();i++) dfs2(v[ROOT][i],ROOT,bes[v[ROOT][i]],i); cout<<(daun/2+daun%2)<<"\n"; sort(Z.begin(),Z.end()); if(daun%2==1) { if(P[Z[daun-1].se]!=ROOT)cout<<Z[daun-1].se<<" "<<ROOT<<"\n"; else { for(i=1;i<=n;i++) if(i!=Z[daun-1].se&&P[Z[daun-1].se]!=i) { cout<<Z[daun-1].se<<" "<<i<<"\n"; break; } } daun--; kel[Z[daun-1].fi.se]--; Z.pop_back(); } sisa=daun/2; for(i=0;i<daun;i++) { vector<pair<ll,ll> > B; for(j=0;j<v[ROOT].size();j++) B.pb(mp(-kel[j],j); sort(B.begin(),B.end()); cout<<isi[B[0].se].back()<<" "<<isi[B[1].se].back(); kel[B[0].se]--; kel[B[1].se]--; isi[B[0].se].pop_back(); isi[B[1].se].pop_back(); } if(sisa)while(1); }

컴파일 시 표준 에러 (stderr) 메시지

net.cpp: In function 'void dfs(long long int, long long int)':
net.cpp:17:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(ii=0;ii<v[aa].size();ii++)
           ~~^~~~~~~~~~~~~
net.cpp: In function 'void dfs2(long long int, long long int, long long int, long long int)':
net.cpp:29:3: error: 'kel' was not declared in this scope
   kel[dd]++;
   ^~~
net.cpp:30:3: error: 'isi' was not declared in this scope
   isi[dd].pb(aa);
   ^~~
net.cpp:30:3: note: suggested alternative: 'sisa'
   isi[dd].pb(aa);
   ^~~
   sisa
net.cpp:34:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(ii=0;ii<v[aa].size();ii++)
           ~~^~~~~~~~~~~~~
net.cpp: In function 'int main()':
net.cpp:56:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<C.size();i++)
          ~^~~~~~~~~
net.cpp:62:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<v[ROOT].size();j++)
           ~^~~~~~~~~~~~~~~
net.cpp:75:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<v[ROOT].size();i++)
          ~^~~~~~~~~~~~~~~
net.cpp:92:3: error: 'kel' was not declared in this scope
   kel[Z[daun-1].fi.se]--;
   ^~~
net.cpp:99:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<v[ROOT].size();j++)
           ~^~~~~~~~~~~~~~~
net.cpp:100:13: error: 'kel' was not declared in this scope
    B.pb(mp(-kel[j],j);
             ^~~
net.cpp:102:9: error: 'isi' was not declared in this scope
   cout<<isi[B[0].se].back()<<" "<<isi[B[1].se].back();
         ^~~
net.cpp:102:9: note: suggested alternative: 'sisa'
   cout<<isi[B[0].se].back()<<" "<<isi[B[1].se].back();
         ^~~
         sisa
net.cpp:103:3: error: 'kel' was not declared in this scope
   kel[B[0].se]--;
   ^~~