Submission #784835

#TimeUsernameProblemLanguageResultExecution timeMemory
784835lucriStations (IOI20_stations)C++17
100 / 100
832 ms792 KiB
#include "stations.h" #include <bits/stdc++.h> std::vector<std::vector<int>>a;; std::vector<int>ins,outs,code; int cur; void pleaca(int nod,int t,bool act,std::vector<std::vector<int>> &a,std::vector<int> &cod) { ins[nod]=cur++; for(auto x:a[nod]) { if(x!=t) pleaca(x,nod,!act,a,cod); } outs[nod]=cur++; if(act==0) cod[nod]=ins[nod]; else cod[nod]=outs[nod]; } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { std::vector<int> labels(n); a.clear(); ins.clear(); outs.clear(); code.clear(); a.resize(n+5); ins.resize(n+5); outs.resize(n+5); code.resize(2*n+5); cur=0; for(int i=0;i<n-1;++i) { a[u[i]].push_back(v[i]); a[v[i]].push_back(u[i]); } pleaca(0,-1,0,a,labels); for(int i=0;i<n;++i) ++code[labels[i]]; for(int i=1;i<2*n;++i) code[i]+=code[i-1]; for(int i=0;i<n;++i) labels[i]=code[labels[i]]; return labels; } int find_next_station(int s, int t, std::vector<int> c) { int ans=c.size(); --ans; if(c[0]<s) { if(t>s||t<=c[0]) return c[0]; while(c[ans]>t) --ans; return c[ans]; } if(s!=1) if(t<s||t>=c[ans]) return c[ans]; ans=0; while(c[ans]<t) ++ans; return c[ans]; }
#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...