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 pii = pair<int, int>;
template<typename T>
using Prior = priority_queue<T>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
const int maxn = 1000 + 5;
vector<int> adj[maxn], lab;
void dfs(int now, int lst) {
// cout << lab[now] << " ";
for (auto x : adj[now]) {
if (x != lst) lab[x] = lab[now] + 1, dfs(x, now);
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
for (int i = 0; i < maxn; ++i) adj[i].clear();
lab.resize(n);
for (int i = 0; i < n-1; ++i) {
adj[u[i]].eb(v[i]), adj[v[i]].eb(u[i]);
}
int maxDeg = 0;
for (int i = 0; i < n; ++i) {
if (adj[i].size() > adj[maxDeg].size()) maxDeg = i;
}
lab[maxDeg] = 0;
int sz = adj[maxDeg].size();
for (int i = 0; i < sz; ++i) {
lab[adj[maxDeg][i]] = i * 1000 + 1;
dfs(adj[maxDeg][i], maxDeg);
}
return lab;
}
int find_next_station(int s, int t, vector<int> c) {
if (s == 0) return t / 1000 * 1000 + 1;
return s > t or s / 1000 != t / 1000 ? c.front() : c.back();
}
# | 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... |