Submission #620780

#TimeUsernameProblemLanguageResultExecution timeMemory
620780wiwihoStations (IOI20_stations)C++14
100 / 100
874 ms796 KiB
#include "stations.h" #include <bits/stdc++.h> #define iter(a) a.begin(), a.end() #define lsort(a) sort(iter(a)) #define gsort(a) sort(iter(a), greater<>()) #define eb emplace_back #define ef emplace_front #define pob pop_back() #define pof pop_front() #define mp make_pair #define F first #define S second #define uni(a) a.resize(unique(iter(a)) - a.begin()) #define printv(a, b) { \ for(auto pv : a) b << pv << " "; \ b << "\n"; \ } using namespace std; typedef long long ll; typedef long double ld; using pii = pair<int, int>; using pll = pair<ll, ll>; template<typename A, typename B> ostream& operator<<(ostream& o, pair<A, B> p){ return o << '(' << p.F << ',' << p.S << ')'; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { vector<vector<int>> g(n); vector<int> ans(n); int ts = -1; function<void(int, int, int)> dfs = [&](int now, int p, int d){ if(d % 2 == 0) ans[now] = ++ts; for(int i : g[now]){ if(i == p) continue; dfs(i, now, d + 1); } if(d % 2 == 1) ans[now] = ++ts; }; for(int i = 0; i < n - 1; i++){ g[u[i]].eb(v[i]); g[v[i]].eb(u[i]); } for(int i = 0; i < n; i++){ if(g[i].size() > 1) continue; dfs(i, i, 0); break; } //cerr << "label "; //printv(ans, cerr); return ans; } int find_next_station(int s, int t, vector<int> c) { if(c.size() == 1) return c[0]; int ty; if(s < c[0]) ty = 0; else ty = 1; //cerr << "find " << s << " -> " << t << "\n"; //cerr << "ty " << ty << "\n"; // 0:in 1:out if(ty == 0){ // c.back(): parent int lst = s; for(int i = 0; i + 1 < (int)c.size(); i++){ //cerr << "range " << c[i] << " : " << lst << " " << c[i] << "\n"; if(lst < t && t <= c[i]) return c[i]; lst = c[i]; } return c.back(); } else{ // c[0]: parent int lst = s; for(int i = (int)c.size() - 1; i > 0; i--){ //cerr << "range " << c[i] << " : " << lst << " " << c[i] << "\n"; if(c[i] <= t && t < lst) return c[i]; lst = 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...