Submission #826690

#TimeUsernameProblemLanguageResultExecution timeMemory
826690sadsaStations (IOI20_stations)C++17
0 / 100
656 ms636 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using ii = pair<int, int>; using vii = vector<ii>; using i64 = int64_t; using vl = vector<i64>; using vvl = vector<vl>; using ll = pair<i64, i64>; using vll = vector<ll>; constexpr int iINF = numeric_limits<int>::max(); constexpr i64 lINF = numeric_limits<i64>::max(); #define RANGE(x) begin(x), end(x) template <typename... T> void DBG(T&&... args) { ((cerr << args << ' '), ...) << '\n'; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) { out << '{'; for (size_t i = 0; i < vec.size()-1; ++i) out << vec[i] << ", "; out << vec.back() << '}'; return out; } template <typename T1, typename T2> ostream &operator<<(ostream &out, const pair<T1, T2> &pr) { out << '(' << pr.first << ", " << pr.second << ')'; return out; } void dfs(int pos, int prv, int &lbl, const vvi &adj, vi &labels) { labels[pos] = lbl; ++lbl; if (adj[pos].size() == 1) return; for (int nxt : adj[pos]) { if (nxt != prv) { dfs(nxt, pos, lbl, adj, labels); } } } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { vi labels(n); vvi adj(n); for (int i = 0; i < n-1; i++) { adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } int root = 0, prv = -1; while (adj[root].size() != 1) { for (int nxt : adj[root]) { if (nxt != prv) { prv = root; root = nxt; break; } } } labels[root] = 0; int lbl = 1; dfs(adj[root][0], root, lbl, adj, labels); return labels; } int find_next_station(int s, int t, std::vector<int> c) { if (c.size() == 1 || t < s) return c[0]; return *lower_bound(RANGE(c), t); }
#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...