# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1239903 | moondarkside | Stations (IOI20_stations) | C++20 | 0 ms | 0 KiB |
#include<bits/stdc++.h>
using namespace std;
#define v vector<int>
#define vv vector<v>
#define I int
vv N;v V;I d(I x,I p,I e,bool t){if(t==false){V[x]=e;I c=1+e;for(I i=0;i<N[x].size();i++){if(N[x][i]!=p){c+=d(N[x][i],x,c,true);}}return c-e;}I c=e;for(I i=0;i<N[x].size();i++){if(N[x][i]!=p){c += d(N[x][i],x,c,false);}}V[x]=c;c++;return c-e;}v label(I n,I k,v u,v P){N=vv(n);for(I i=0;i<n-1;i++){N[u[i]].push_back(P[i]);N[P[i]].push_back(u[i]);}V=v(n);d(0,-1,0,false);return V;}I find_N_station(I s,I t,v c){I l=c.size()-1;if(s<c[0]){if(t<s){return c[l];}for(I i=0;i<l;i++){if(t<=c[i]){return c[i];}}return c[l];}if(t>s){return c[0];}for(I i=l;i>0;i--){if(t>=c[i]){return c[i];}}return c[0];}