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 <bits/stdc++.h>
#include "stations.h"
using namespace std;
vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
vector<int> labels(n);
vector<vector<int> > 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 ti = 0, to = 0;
auto DFS = [&] (auto DFS, int u, int par) -> void
{
labels[u] = ti;
ti++;
for (int i = 0; i < (int)adj[u].size(); i++) {
if (adj[u][i] == par) {
adj[u].erase(adj[u].begin() + i);
break;
}
}
if (adj[u].size()) {
for (int i = 0; i < (int)adj[u].size() - 1; i++) {
DFS(DFS, adj[u][i], u);
}
DFS(DFS, adj[u].back(), u);
}
labels[u] = labels[u] * 1000 + to;
to++;
};
DFS(DFS, 0, -1);
return labels;
}
int find_next_station(int s, int t, vector<int> c)
{
pair<int,int> st = {s / 1000, s % 1000};
pair<int,int> en = {t / 1000, t % 1000};
vector<pair<int,int> > adj;
for (int x : c) {
adj.push_back(make_pair(x / 1000, x % 1000));
}
pair<int,int> par = make_pair(-1, -1);
if (st.first) {
for (pair<int,int> p : adj) {
if (!(st.first <= p.first && p.second <= st.second)) {
par = p;
break;
}
}
}
if (!(st.first <= en.first && en.second <= st.second)) return par.first * 1000 + par.second;
for (pair<int,int> p : adj) {
if (par == p) continue;
if (p.first <= en.first && en.second <= p.second) return p.first * 1000 + p.second;
}
return -1;
}
# | 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... |