Task: | Distances |
Sender: | Victor |
Submission time: | 2021-01-30 16:58:44 +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>using namespace std;#define rep(i, a, b) for (int i = a; i < (b); ++i)#define per(i, a, b) for (int i = a - 1; i >= (b); --i)#define trav(a, x) for (auto &a : x)#define all(x) x.begin(), x.end()#define sz(x) x.size()#define pb push_back#define umap unordered_map#define uset unordered_set#define INF 1000000000typedef pair<int, int> ii;typedef pair<int, ii> iii;typedef vector<int> vi;typedef vector<ii> vii;typedef long long ll;vi graph[101];int n, tc, ans[101], indx, dist;void solve(int u, int p) {bool add = true;if(dist==3){add=false;ans[indx++]=u;dist=0;}trav(v, graph[u]) {if (v == p) continue;++dist;solve(v, u);}if (add) {ans[indx++] = u;dist = 1;}}int main() {ios::sync_with_stdio(0);cin.tie(NULL);cin >> tc;int u, v;while (tc--) {fill(graph, graph + 101, vi());cin >> n;rep(i, 0, n-1) {cin >> u >> v;graph[u].pb(v);graph[v].pb(u);}indx = dist = 0;solve(1, 0);rep(i,0,n)cout<<ans[i]<<' ';cout<<endl;}return 0;}
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 |
---|
3 5 6 2 7 8 4 1 8 2 7 3 6 4 5 1 4 6 7 2 5 8 3 1 3 8 2 4 7 6 5 1 6 4 2 5 7 3 8 1 ... 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 |
---|
60 81 17 5 55 71 59 24 39 52 3... Truncated |