Submission #350009

#TimeUsernameProblemLanguageResultExecution timeMemory
350009Osama_AlkhodairyStations (IOI20_stations)C++17
100 / 100
1020 ms1348 KiB
#include <bits/stdc++.h> #include "stations.h" //~ #include "stub.cpp" using namespace std; const int N = 1001; int st[N], en[N], dep[N], dfstime; vector <int> g[N]; void dfs(int node, int pnode){ if(dep[node] % 2) st[node] = dfstime++; for(auto &i : g[node]){ if(i == pnode) continue; dep[i] = dep[node] + 1; dfs(i, node); } if(dep[node] % 2 == 0) en[node] = dfstime++; } vector<int> label(int n, int k, vector<int> u, std::vector<int> v) { dfstime = 0; for(int i = 0 ; i < n ; i++){ g[i].clear(); } for(int i = 0 ; i < (int)u.size() ; i++){ g[u[i]].push_back(v[i]); g[v[i]].push_back(u[i]); } dfs(0, -1); vector <int> ret(n); for(int i = 0 ; i < n ; i++){ if(dep[i] % 2) ret[i] = st[i]; else ret[i] = en[i]; } return ret; } int find_next_station(int s, int t, vector<int> c) { if(c.size() == 1) return c[0]; if(c.back() > s){ int p = c.back(); c.pop_back(); c.insert(c.begin(), s); for(int i = 0 ; i + 1 < (int)c.size() ; i++){ if(c[i] <= t && t <= c[i + 1]){ return c[i + 1]; } } return p; } else{ int p = c[0]; c.erase(c.begin()); c.push_back(s); for(int i = 0 ; i + 1 < (int)c.size() ; i++){ if(c[i] <= t && t < c[i + 1]){ return c[i]; } } return p; } }
#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...