Submission #772647

#TimeUsernameProblemLanguageResultExecution timeMemory
772647khshgStations (IOI20_stations)C++14
0 / 100
802 ms676 KiB
#include"stations.h" #include<bits/stdc++.h> using namespace std; vector<vector<int>> adj; int lo, hi = -1; vector<int> L, R; vector<bool> flor; void dfs(int s, int p, bool flr) { flor[s] = flr; bool leaf = 1; L[s] = 0x3f3f3f3f; R[s] = -0x3f3f3f3f; for(auto& u : adj[s]) { if(u == p) continue; leaf = 0; dfs(u, s, flr ^ 1); L[s] = min(L[s], L[u]); R[s] = max(R[s], R[u]); } if(leaf) { ++hi; L[s] = R[s] = hi; } else { if(flr) { ++hi; R[s] = hi; } else { --lo; L[s] = lo; } } } vector<int> label(int N, int K, vector<int> u, vector<int> v) { flor.resize(N); L.resize(N); R.resize(N); adj.resize(N); for(auto& I : adj) I.clear(); for(int i = 0; i < (int)u.size(); ++i) { adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } dfs(0, -1, 0); vector<int> labels(N); for(int i = 0; i < N; ++i) labels[i] = (flor[i] ? R[i] - lo: L[i] - lo); return labels; } int find_next_station(int s, int t, vector<int> c) { if(s == 0) { pair<int, int> T = {t, t}; vector<pair<int, int>> C((int)c.size()); C[0] = {1, c[0]}; for(int i = 1; i < (int)c.size(); ++i) { C[i] = {c[i - 1] + 1, c[i]}; } int ans = -1; // sus??? for(int i = 0; i < (int)c.size(); ++i) { if(C[i].first <= T.second && C[i].second >= T.second) ans = i; } return c[ans]; } if(s < c[0]) { pair<int, int> S = {s, c.back() - 1}, T = {t, t}; vector<pair<int, int>> C((int)c.size()); C[0] = {s + 1, c[0]}; C.back() = {s, c.back()}; for(int i = 1; i + 1 < (int)c.size(); ++i) { C[i] = {c[i - 1] + 1, c[i]}; } int par = -1, ans = -1; for(int i = 0; i < (int)c.size(); ++i) { if(C[i].first <= S.first && C[i].second >= S.second) par = i; else if(C[i].first <= T.second && C[i].second >= T.second) ans = i; } return (ans == -1 ? c[par] : c[ans]); } pair<int, int> S = {c[0] + 1, s}, T = {t, t}; vector<pair<int, int>> C((int)c.size()); C.back() = {c.back(), s - 1}; C[0] = {c[0], s + 1}; for(int i = 1; i + 1 < (int)c.size(); ++i) { C[i] = {c[i], c[i + 1] - 1}; } int par = -1, ans = -1; for(int i = 0; i < (int)c.size(); ++i) { if(C[i].first <= S.first && C[i].second >= S.second) par = i; else if(C[i].first <= T.second && C[i].second >= T.second) ans = i; } return (ans == -1 ? c[par] : c[ans]); return 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...