Task: | Distances |
Sender: | lookcook |
Submission time: | 2021-01-30 18:16:28 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | WRONG ANSWER | 0.01 s | 1, 2 | details |
#2 | WRONG ANSWER | 0.01 s | 2 | details |
Code
#include <bits/stdc++.h> #define int long long using namespace std; const int maxn = 105; vector<int> adj[maxn]; queue<int> q; void dfs(int u, int par, int cur) { int childs = adj[u].size()-1; if (u == par) childs++; if (cur == 2 || childs>1) { q.push(u); for (int v : adj[u]) { if (v == par) continue; dfs(v,u,0); } } else { for (int v : adj[u]) { if (v == par) continue; dfs(v,u,cur+1); } q.push(u); } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= n; i++) adj[i] = {}; for (int i = 0; i < n-1; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } dfs(1,1,0); while (!q.empty()) { int u = q.front(); q.pop(); cout << u << ' '; } cout << '\n'; } } /* */
Test details
Test 1
Group: 1, 2
Verdict: WRONG ANSWER
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 |
---|
8 3 2 5 6 7 4 1 1 8 2 7 3 5 6 4 1 4 8 7 2 5 6 3 1 6 3 8 2 4 7 5 1 6 3 5 2 7 4 8 ... Truncated |
Test 2
Group: 2
Verdict: WRONG ANSWER
input |
---|
100 100 37 59 81 37 44 81 ... |
correct output |
---|
1 99 82 81 59 5 71 55 17 24 13... |
user output |
---|
1 60 82 44 81 37 17 5 55 71 59... Truncated |