Submission #966983

#TimeUsernameProblemLanguageResultExecution timeMemory
966983emad234Stations (IOI20_stations)C++17
0 / 100
1 ms540 KiB
#include "stations.h" #include <bits/stdc++.h> #define ll long long #define F first #define S second #define pii pair<int, int> using namespace std; vector<int> labelss, pre, post; vector<vector<int>> gr; int id; void dfs(int u, int par) { pre[u] = ++id; for (auto x : gr[u]) { if (x == par) continue; dfs(x, u); } post[u] = ++id; } void labeling(int u, int par, int d) { if (d % 2) labelss[u] = pre[u]; else labelss[u] = post[u]; cout << labelss[u] << ' '; for (auto x : gr[u]) { if (x == par) continue; labeling(x, u, d + 1); } } vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { gr.clear(); post.clear(); pre.clear(); labelss.clear(); gr.resize(n + 1); labelss.resize(n); post.resize(n); pre.resize(n); for (int i = 0; i < n - 1; i++) { gr[u[i]].push_back(v[i]); gr[v[i]].push_back(u[i]); } dfs(0, -1); labeling(0, -1, 0); cout << '\n'; return labelss; } int find_next_station(int s, int t, std::vector<int> c) { bool pst = 1; int root = -1; for (auto x : c) { if (x > s) pst = 0; } for (auto x : c) { if (pst) root == -1 ? root = x : root = min(root, x); else root = max(x, root); } int id = root; if (pst) { for (auto x : c) { if (x > t) break; else id = x; } if (s < t) id = root; } else { for (auto x : c) { if (x > t) { id = x; break; } } } return id; }
#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...