Submission #738518

#TimeUsernameProblemLanguageResultExecution timeMemory
738518bobthebuilderStations (IOI20_stations)C++17
100 / 100
1043 ms10236 KiB
#include "stations.h" #include<bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define pb push_back #define lowb(x) (x&(-x)) #define ALL(_x) _x.begin(),_x.end() #define pii pair<int,int> #define f first #define s second #define SORT_UNIQUE(x) sort(ALL(x)),x.erase(unique(ALL(x)),x.end()) #define ll long long #define MNTO(x,y) x=min(x,y) #define MXTO(x,y) x=max(x,y) const int maxn=2e5+5; const int INF=0x3f3f3f3f; int dep[maxn]; vector<int> g[maxn]; int in[maxn],out[maxn]; int cur=0; void dfs(int u,int p){ in[u]=(cur++); for(int x:g[u]){ if(x==p) continue; dep[x]=dep[u]+1; dfs(x,u); } out[u]=cur-1; } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { cur=0; REP(i,n) g[i].clear(); REP(i,n-1){ g[u[i]].pb(v[i]),g[v[i]].pb(u[i]); } dfs(0,-1); vector<pair<pii,int>> ans; REP(i,n){ if(dep[i]%2) ans.pb({{in[i],-dep[i]},i}); else ans.pb({{out[i],-dep[i]},i}); } vector<int> vv(n,0); sort(ALL(ans)); REP(i,n){ vv[ans[i].s]=i; } return vv; } int find_next_station(int s, int t, std::vector<int> c) { if(s<c[0]){ c.emplace(c.begin(),s); //s labeled in REP1(i,sz(c)-1){ if(t<=c[i] and t>c[i-1]){ return c[i]; } } return c.back(); } else{ c.pb(s); REP1(i,sz(c)-2){ if(t>=c[i] and t<c[i+1]){ return c[i]; } } return c[0]; } }
#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...