Submission #390840

#TimeUsernameProblemLanguageResultExecution timeMemory
390840AlexPop28Stations (IOI20_stations)C++14
100 / 100
1172 ms736 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; void DFS(int node, int par, int depth, int &timer, vector<int> &ans, const vector<vector<int>> &adj) { if (depth == 0) ans[node] = timer++; for (auto &x : adj[node]) { if (x == par) continue; DFS(x, node, 1 - depth, timer, ans, adj); } if (depth == 1) ans[node] = timer++; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { vector<int> ans(n); vector<vector<int>> adj(n); for (int i = 0; i < n - 1; ++i) { adj[u[i]].emplace_back(v[i]); adj[v[i]].emplace_back(u[i]); } int timer = 0; DFS(0, -1, 0, timer, ans, adj); return ans; } int find_next_station(int s, int t, vector<int> c) { if ((int)c.size() == 1) { return c[0]; } if (s < c[0]) { // sunt nod de in-time // c.back() e par if (s < t && t <= c[0]) { return c[0]; } for (int i = 0; i + 1 < (int)c.size() - 1; ++i) { if (c[i] < t && t <= c[i + 1]) return c[i + 1]; } return c.back(); } else { // sunt nod de out-time assert(s > c.back()); // c[0] e par if (c.back() <= t && t < s) { return c.back(); } for (int i = 1; i + 1 < (int)c.size(); ++i) { if (c[i] <= t && 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...