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>
using i64 = long long;
#ifdef DEBUG
#include "../../debug.h"
#else
#define debug(...) void(23)
#endif
constexpr int max_N = int(2E5) + 5;
int N;
int A[max_N], B[max_N], ans[max_N];
std::vector<int> adj[max_N];
int cur = 0;
std::vector<int> p;
void solve(int v) {
ans[v] = p[cur++];
for (auto u : adj[v]) {
adj[u].erase(std::find(adj[u].begin(), adj[u].end(), v));
solve(u);
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> N;
for (int i = 0; i < N - 1; ++i) {
int u, v;
std::cin >> u >> v;
--u, --v;
adj[u].emplace_back(v);
adj[v].emplace_back(u);
}
for (int i = 0; i < N; ++i) {
std::cin >> A[i] >> B[i];
++A[i], ++B[i];
}
p.assign(N, 0);
std::iota(p.begin(), p.end(), 0);
std::sort(p.begin(), p.end(), [&](auto lhs, auto rhs) {
return std::pair{A[lhs], B[lhs]} < std::pair{A[rhs], B[rhs]};
});
solve(0);
for (int i = 0; i < N; ++i) {
std::cout << ans[i] + 1 << " \n"[i == N - 1];
}
return 0;
}
# | 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... |