제출 #833737

#제출 시각아이디문제언어결과실행 시간메모리
833737Johann기지국 (IOI20_stations)C++14
76 / 100
908 ms796 KiB
#include "stations.h" #include "bits/stdc++.h" using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() int N, K, idx; vvi adj; vi in, out, parity; void dfs(int v, int p) { in[v] = idx++; parity[v] = parity[p] ^ 1; for (int u : adj[v]) if (u != p) dfs(u, v); out[v] = idx++; }; std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { K = k; N = n; adj.clear(); adj.resize(N); for (int i = 0; i < N - 1; ++i) adj[u[i]].push_back(v[i]), adj[v[i]].push_back(u[i]); idx = 0; in.assign(N, -1), out.assign(N, -1), parity.assign(N, 0); dfs(0, 0); vi labels(N); for (int i = 0; i < n; i++) labels[i] = (parity[i]) ? in[i] : out[i]; return labels; } int find_next_station(int s, int t, std::vector<int> c) { if (s < c[0]) { // s has in parity if (t < s) return c.back(); // parent with highest out value for (int i = 0; i < sz(c); ++i) { if (t <= c[i]) return c[i]; } return c.back(); } else { // s has out parity if (t > s) return c[0]; for (int i = sz(c) - 1; i >= 0; --i) if (t >= c[i]) 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...