Submission #531840

#TimeUsernameProblemLanguageResultExecution timeMemory
531840EqualTurtleStations (IOI20_stations)C++14
100 / 100
939 ms52652 KiB
#include "stations.h" #include <vector> using namespace std; constexpr int MAXN = 1e6 + 7; vector <int> graf[MAXN]; int order; int depth[MAXN]; vector<int> labels; bool odw[MAXN]; void dfs(int w) { odw[w] = true; for (int i : graf[w]) { if (odw[i]) continue; depth[i] = depth[w] + 1; if (depth[i] % 2 == 0) labels[i] = order++; dfs(i); if (depth[i] % 2 == 1) labels[i] = order++; } } vector<int> label(int n, int k, vector<int> u, vector<int> v) { while (labels.size()) labels.pop_back(); for (int i = 0; i < MAXN; i++){ while(graf[i].size()) graf[i].pop_back(); depth[i] = 0; odw[i] = false; } labels.resize(n); order = 1; for (int i = 0; i < (int)u.size(); i++){ graf[u[i]].push_back(v[i]); graf[v[i]].push_back(u[i]); } dfs(0); return labels; } int find_next_station(int s, int t, vector<int> c) { if (c.size() == 1) return c[0]; for (int i : c) if (i == t) return i; if (s > c.back()) { if (t > s) return c[0]; for (int i = 1; i < (int)c.size() - 1; i++) { if (c[i] < t && c[i + 1] > t) return c[i]; } if (c.back() < t) return c.back(); return c[0]; } else { if (t > c[c.size() - 2] || t < s) return c.back(); for (int i = 0; i < (int)c.size(); i++) { if (c[i] > t) return c[i]; } return c.back(); } }
#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...