Submission #432285

#TimeUsernameProblemLanguageResultExecution timeMemory
432285MlxaStations (IOI20_stations)C++14
100 / 100
952 ms732 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) x.begin(), x.end() #define mp make_pair #define mt make_tuple #define x first #define y second #include "stations.h" vector<int> label(int n, int k, vector<int> eu, vector<int> ev) { assert(k >= n - 1); vector<int> labels(n), order; vector<vector<int>> g(n); for (int i = 0; i < n - 1; ++i) { g[ev[i]].push_back(eu[i]); g[eu[i]].push_back(ev[i]); } function<void(int, int, bool)> dfs = [&](int v, int p, bool in) { if (in) { order.push_back(v); } for (int u : g[v]) { if (u != p) { dfs(u, v, !in); } } if (!in) { order.push_back(v); } }; dfs(0, 0, 1); for (int i = 0; i < n; ++i) { labels[order[i]] = i; } return labels; } int find_next_station(int s, int t, vector<int> c) { assert(is_sorted(all(c))); assert(s != t); if (c.size() == 1) { return c[0]; } if (c[0] < s) { assert(c.back() < s); if (t < c.front()) { return c.front(); } for (int i = 0; i + 1 < (int)c.size(); ++i) { if (c[i] <= t && t < c[i + 1]) { return c[i]; } } if (c.back() <= t && t < s) { return c.back(); } assert(t > s); return c[0]; } else { assert(c.front() > s); if (t < s) { return c.back(); } for (int e : c) { if (t <= e) { return e; } } return c.back(); } } #ifdef LC #include "stub.cpp" #endif
#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...