Task: | Distances |
Sender: | wlz |
Submission time: | 2021-01-31 17:17:06 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 29 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 29 |
#2 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2 | details |
#2 | TIME LIMIT EXCEEDED | -- | 2 | details |
Code
#include <bits/stdc++.h> using namespace std; vector< vector<int> > g; void dfs(int u, int p, vector<int> &dist) { for (auto& v : g[u]) { if (v != p) { dist[v] = dist[u] + 1; dfs(v, u, dist); } } } int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; g.assign(n + 1, vector<int>()); for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } vector< vector<int> > dist(n + 1, vector<int>(n + 1, 0)); for (int i = 1; i <= n; i++) dfs(i, -1, dist[i]); vector<int> perm(n); iota(perm.begin(), perm.end(), 1); do { int mx = 0; for (int i = 0; i < n - 1; i++) mx = max(mx, dist[perm[i]][perm[i + 1]]); if (mx <= 3) { break; } } while (next_permutation(perm.begin(), perm.end())); for (auto& x : perm) cout << x << ' '; cout << '\n'; } return 0; }
Test details
Test 1
Group: 1, 2
Verdict: ACCEPTED
input |
---|
100 8 5 2 2 3 3 7 ... |
correct output |
---|
1 8 2 5 6 7 3 4 1 7 2 8 3 6 4 5 1 4 6 2 7 5 8 3 1 8 3 2 4 7 6 5 1 6 4 7 5 2 3 8 ... |
user output |
---|
1 3 2 4 7 5 6 8 1 3 2 8 7 5 4 6 1 3 2 5 7 8 6 4 1 2 3 4 5 6 7 8 1 3 2 4 6 8 7 5 ... Truncated |
Test 2
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
100 100 37 59 81 37 44 81 ... |
correct output |
---|
1 99 82 81 59 5 71 55 17 24 13... |
user output |
---|
(empty) |