# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
497804 | 2021-12-23T21:25:06 Z | MilosMilutinovic | Stations (IOI20_stations) | C++14 | 1 ms | 564 KB |
#include <bits/stdc++.h> using namespace std; const int N = 1005; const int L = 10; int par[N][L], dep[N]; std::vector<int> G[N]; void dfs_init(int u, int p) { par[u][0] = p; for (int i = 1; i < L; ++i) if (par[u][i - 1] != -1) par[u][i] = par[par[u][i - 1]][i - 1]; for (int v : G[u]) if (v != p) dep[v] = dep[u] + 1, dfs_init(v, u); } int lca(int u, int v) { if (dep[u] < dep[v]) swap(u, v); for (int i = L - 1; ~i; --i) if (par[u][i] != -1 && dep[par[u][i]] >= dep[v]) u = par[u][i]; if (u == v) return u; for (int i = L - 1; ~i; --i) if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i]; return (u == v ? u : par[u][0]); } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { for (int i = 0; i < n; ++i) { G[u[i]].push_back(v[i]); G[v[i]].push_back(u[i]); } dfs_init(0, 0); } int find_next_station(int s, int t, std::vector<int> c) { std::vector<int> path; int L = lca(s, t); while (dep[s] >= dep[L]) { path.push_back(s); s = par[s][0]; } while (dep[t] >= dep[L]) { path.push_back(t); t = par[t][0]; } int node = -1; for (int i : path) for (int j : c) if (i == j) node = j; return node; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 456 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 564 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 448 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 416 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 436 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |