This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
}
}
int lbl = labels[root] = 0;
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) return c[0];
if (s == 0) {
if (t == 0) return 0;
} else if (t < s) return c[0];
return *lower_bound(RANGE(c), t);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |