Submission #246324

#TimeUsernameProblemLanguageResultExecution timeMemory
246324vanicTorrent (COI16_torrent)C++14
Compilation error
0 ms0 KiB
#include <iostream> #include <cstdio> #include <math.h> #include <algorithm> #include <bitset> using namespace std; const int maxn=3e5+5; int n, a, b; vector < int > ms[maxn]; vector < int > put; int val[maxn]; bitset < maxn > bio; bool dfs(int x, int prosl){ put.push_back(x); if(x==b){ return 1; } for(int i=0; i<ms[x].size(); i++){ if(ms[x][i]!=prosl){ if(dfs(ms[x][i], x)){ return 1; } } } put.pop_back(); return 0; } int siri(int x, int prosl){ if(bio[x]){ // cout << "NE" << endl; return 0; } vector < int > svi; for(int i=0; i<ms[x].size(); i++){ if(ms[x][i]!=prosl && !bio[ms[x][i]]){ svi.push_back(siri(ms[x][i], x)); } } if(svi.empty()){ val[x]=1; return 1; } sort(svi.begin(), svi.end()); val[x]=0; for(int i=0; i<svi.size(); i++){ val[x]=max(val[x], svi[i]+(int)svi.size()-i); } // cout << "sirim " << x << " " << val[x] << " " << svi.size() << endl;; return val[x]; } int binary1(){ int lo=1, hi=put.size()-1; int mid; while(lo<hi){ mid=(lo+hi)/2+1; bio[mid]=1; if(siri(put[1], a)>val[a]){ hi=mid-1; } else{ lo=mid; } bio[mid]=0; } return lo; } int binary2(){ int lo=0, hi=put.size()-2; int mid; while(lo<hi){ mid=(lo+hi)/2; bio[mid]=1; if(siri(put[put.size()-2], b)>val[b]){ lo=mid+1; } else{ hi=mid; } bio[mid]=0; } return lo; } int ternary(int lo, int hi){ int mid; int val1, val2; int val3, val4; // cout << put[1] << " " << put[put.size()-2] << '\n'; while(lo<hi){ mid=(lo+hi)/2+1; bio[put[mid]]=1; // cout << "poc" << endl; val1=siri(put[1], a); bio[put[mid]]=0; bio[put[mid-1]]=1; // cout << "poc" << endl; val2=siri(put[put.size()-2], b); // cout << "poc" << endl; val3=siri(put[1], a); bio[put[mid-1]]=0; bio[put[mid-2]]=1; // cout << "poc" << endl; val4=siri(put[put.size()-2], b); bio[put[mid-2]]=0; // cout << mid << endl; // cout << val1 << " " << val2 << " " << val3 << " " << val4 << '\n'; if(max(val1, val2)>max(val3, val4)){ hi=mid-1; } else{ lo=mid; } } return min(max(val1, val2), max(val3, val4)); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> a >> b; a--; b--; int c, d; for(int i=0; i<n-1; i++){ cin >> c >> d; c--; d--; ms[c].push_back(d); ms[d].push_back(c); } dfs(a, a); siri(a, put[1]); siri(b, put[put.size()-2]); int lo, hi; lo=binary1(); hi=binary2(); int sol=1e9; if(hi+1<=lo){ if(hi==0){ sol=min(sol, max(val[a]-1, val[b])); } if(lo==put.size()-1){ sol=min(sol, max(val[a], val[b]-1)); } sol=min(sol, max(val[a], val[b])); } else{ sol=ternary(lo, hi+1); } cout << sol << '\n'; return 0; }

Compilation message (stderr)

torrent.cpp:12:1: error: 'vector' does not name a type; did you mean 'perror'?
 vector < int > ms[maxn];
 ^~~~~~
 perror
torrent.cpp:13:1: error: 'vector' does not name a type; did you mean 'perror'?
 vector < int > put;
 ^~~~~~
 perror
torrent.cpp: In function 'bool dfs(int, int)':
torrent.cpp:18:2: error: 'put' was not declared in this scope
  put.push_back(x);
  ^~~
torrent.cpp:18:2: note: suggested alternative: 'putw'
  put.push_back(x);
  ^~~
  putw
torrent.cpp:22:17: error: 'ms' was not declared in this scope
  for(int i=0; i<ms[x].size(); i++){
                 ^~
torrent.cpp: In function 'int siri(int, int)':
torrent.cpp:38:2: error: 'vector' was not declared in this scope
  vector < int > svi;
  ^~~~~~
torrent.cpp:38:2: note: suggested alternative: 'perror'
  vector < int > svi;
  ^~~~~~
  perror
torrent.cpp:38:11: error: expected primary-expression before 'int'
  vector < int > svi;
           ^~~
torrent.cpp:39:17: error: 'ms' was not declared in this scope
  for(int i=0; i<ms[x].size(); i++){
                 ^~
torrent.cpp:41:4: error: 'svi' was not declared in this scope
    svi.push_back(siri(ms[x][i], x));
    ^~~
torrent.cpp:41:4: note: suggested alternative: 'siri'
    svi.push_back(siri(ms[x][i], x));
    ^~~
    siri
torrent.cpp:44:5: error: 'svi' was not declared in this scope
  if(svi.empty()){
     ^~~
torrent.cpp:44:5: note: suggested alternative: 'siri'
  if(svi.empty()){
     ^~~
     siri
torrent.cpp:48:7: error: 'svi' was not declared in this scope
  sort(svi.begin(), svi.end());
       ^~~
torrent.cpp:48:7: note: suggested alternative: 'siri'
  sort(svi.begin(), svi.end());
       ^~~
       siri
torrent.cpp: In function 'int binary1()':
torrent.cpp:58:15: error: 'put' was not declared in this scope
  int lo=1, hi=put.size()-1;
               ^~~
torrent.cpp:58:15: note: suggested alternative: 'putw'
  int lo=1, hi=put.size()-1;
               ^~~
               putw
torrent.cpp: In function 'int binary2()':
torrent.cpp:75:15: error: 'put' was not declared in this scope
  int lo=0, hi=put.size()-2;
               ^~~
torrent.cpp:75:15: note: suggested alternative: 'putw'
  int lo=0, hi=put.size()-2;
               ^~~
               putw
torrent.cpp: In function 'int ternary(int, int)':
torrent.cpp:98:7: error: 'put' was not declared in this scope
   bio[put[mid]]=1;
       ^~~
torrent.cpp:98:7: note: suggested alternative: 'putw'
   bio[put[mid]]=1;
       ^~~
       putw
torrent.cpp: In function 'int main()':
torrent.cpp:137:3: error: 'ms' was not declared in this scope
   ms[c].push_back(d);
   ^~
torrent.cpp:141:10: error: 'put' was not declared in this scope
  siri(a, put[1]);
          ^~~
torrent.cpp:141:10: note: suggested alternative: 'putw'
  siri(a, put[1]);
          ^~~
          putw