Submission #424082

#TimeUsernameProblemLanguageResultExecution timeMemory
424082SupersonicStations (IOI20_stations)C++14
100 / 100
1061 ms884 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; vector<int> g[1005];int l[1005];int z[1005]; int w(int n,int a){ int c=1; for(auto i:g[n])if(i!=a)c+=w(i,n); z[n]=c;return c; } void d(int n,int a,int e,bool p){ if(p)l[n]=a+z[n]; else l[n]=a-z[n]; int f=l[n];//cerr<<n<<' '<<f<<endl; for(auto i:g[n])if(i!=e){d(i,f,n,!p);f=l[i];} } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { for(int i=0;i<n-1;i++){g[u[i]].push_back(v[i]);g[v[i]].push_back(u[i]);} w(0,n);d(0,n,n,0);vector<int> r; for(int i=0;i<n;i++){r.push_back(l[i]);g[i].clear();} return r; } int find_next_station(int s, int t, std::vector<int> c) { if(s<c[0]){ if(t<s||t>=c.back())return c.back(); for(auto i:c)if(t<=i)return i; } else{ reverse(c.begin(),c.end()); if(t>s||t<=c.back())return c.back(); for(auto i:c)if(t>=i)return i; } exit(1); }
#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...