Submission #304916

#TimeUsernameProblemLanguageResultExecution timeMemory
304916kevinsogoStations (IOI20_stations)C++17
100 / 100
1394 ms1088 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; struct Labeller { int n, ord = 0; vector<vector<int>> adj; vector<int> labels; Labeller(int n, const vector<int>& u, const vector<int>& v): n(n), adj(n), labels(n) { for (int i = 0; i < n - 1; i++) { adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } preposterous(0, -1, false); assert(ord == n); } void preposterous(int s, int p, bool x) { if (x) labels[s] = ord++; for (int t : adj[s]) if (t != p) preposterous(t, s, !x); if (!x) labels[s] = ord++; } }; vector<int> label(int n, int k, vector<int> u, vector<int> v) { return Labeller(n, u, v).labels; } int find_next_station(int s, int t, vector<int> c) { if (s > c.back()) reverse(c.begin(), c.end()); for (int u : c) if (min(u, s) <= t && t <= max(u, s)) return u; 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...