Submission #419468

#TimeUsernameProblemLanguageResultExecution timeMemory
419468vkgainzStations (IOI20_stations)C++17
0 / 100
902 ms656 KiB
#include <bits/stdc++.h> using namespace std; vector<int> st, en, d; vector<vector<int>> adj; int t; void dfs(int curr, int par) { st[curr] = t++; for(int next : adj[curr]) { if(next == par) continue; d[next] = d[curr] + 1; dfs(next, curr); } en[curr] = t++; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { adj.clear(), st.clear(), en.clear(), d.clear(); adj.resize(n); st.resize(n); en.resize(n); d.resize(n); for(int i = 0; i < n - 1; i++) { adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } vector<int> ans(n); t = 0; dfs(0, -1); for(int i = 0; i < n; i++) { if(d[i] % 2 == 0) ans[i] = st[i] / 2; else ans[i] = en[i] / 2; } return ans; } int find_next_station(int s, int t, vector<int> c) { bool odd = false; s *= 2; t *= 2; for(int i = 0; i < (int) c.size(); i++) { c[i] *= 2; } if(c[0] < s) odd = true; if(c.size() == 1) return c[0] / 2; if(odd) { for(int i = 1; i < (int) c.size(); i++) { if(t >= c[i] && t <= s) return c[i] / 2; } return c[0] / 2; } else { for(int i = (int) c.size() - 1; i >= 0; i--) { if(t <= c[i] && t >= s) return c[i] / 2; } return c[0] / 2; } return -1; }
#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...