Submission #373961

#TimeUsernameProblemLanguageResultExecution timeMemory
373961Jarif_RahmanStations (IOI20_stations)C++17
100 / 100
1079 ms1092 KiB
#include "stations.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; vector<vector<int>> v; vector<int> lb, sz; int in = 0; void dfs(int nd, int ss, int d){ if(d%2 == 0) lb[nd] = in++; for(int x: v[nd]) if(x != ss) dfs(x, nd, d+1); if(d%2 == 1) lb[nd] = in++; } vector<int> label(int n, int k, vector<int> aa, vector<int> bb){ in = 0; v.assign(n, {}); lb.assign(n, -1); for(int i = 0; i < n-1; i++){ v[aa[i]].pb(bb[i]); v[bb[i]].pb(aa[i]); } dfs(0, -1, 0); return lb; } int find_next_station(int s, int t, vector<int> c){ sort(c.begin(), c.end()); if(s > c[0]){ c.pb(s); for(int i = 1; i < (int)c.size() - 1; i++){ if(t >= c[i] && t < c[i+1]) return c[i]; } return c[0]; } else{ reverse(c.begin(), c.end()); c.pb(s); for(int i = (s==0); i < (int)c.size()-1; i++){ if(t <= c[i] && 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...