Submission #387825

#TimeUsernameProblemLanguageResultExecution timeMemory
387825WLZStations (IOI20_stations)C++14
100 / 100
897 ms852 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; int dfs_cnt = 0; vector< vector<int> > g; vector<int> d, dfs_in, dfs_out; void dfs(int u, int p) { dfs_in[u] = dfs_cnt++; for (auto& v : g[u]) { if (v != p) { d[v] = d[u] + 1; dfs(v, u); } } dfs_out[u] = dfs_cnt++; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { g.assign(n, {}); d.assign(n, 0); for (int i = 0; i < n - 1; i++) { g[u[i]].push_back(v[i]); g[v[i]].push_back(u[i]); } dfs_in.assign(n, 0); dfs_out.assign(n, 0); dfs(0, -1); set<int> st; for (int i = 0; i < n; i++) { if (d[i] % 2 == 0) st.insert(dfs_in[i]); else st.insert(dfs_out[i]); } int cur = 0; map<int, int> mp; for (auto& x : st) mp[x] = cur++; vector<int> ans(n); for (int i = 0; i < n; i++) { if (d[i] % 2 == 0) ans[i] = mp[dfs_in[i]]; else ans[i] = mp[dfs_out[i]]; } return ans; } int find_next_station(int s, int t, vector<int> c) { for (auto& x : c) if (x == t) return t; sort(c.begin(), c.end()); if (s < c[0]) { // in for (int i = 0; i < (int) c.size() - 1; i++) if (s < t && t < c[i]) return c[i]; return c.back(); } else { // out for (int i = (int) c.size() - 1; i >= 1; i--) if (c[i] < t && t < s) 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...