Task: | Distances |
Sender: | kostia244 |
Submission time: | 2021-01-30 20:09:39 +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 |
Compiler report
input/code.cpp: In function 'std::array<int, 2> dfs(int, int, int)': input/code.cpp:15:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int i = 1; i < chi.size(); i++) { ~~^~~~~~~~~~~~
Code
#include<bits/stdc++.h> #define all(x) x.begin(), x.end() using namespace std; using ll = long long; const int maxn = 1<<18; int n; vector<vector<int>> g; vector<int> nxt; array<int, 2> dfs(int v, int p, int type) { if(g[v].size() == 1 && p != -1) return {v, v}; vector<array<int, 2>> chi; for(auto &i : g[v]) if(i != p) { chi.push_back(dfs(i, v, type^1)); } for(int i = 1; i < chi.size(); i++) { nxt[chi[i-1][1]] = chi[i][0]; } if(type) { nxt[chi.back()[1]] = v; return {chi[0][0], v}; } nxt[v] = chi[0][0]; return {v, chi.back()[1]}; } int main() { cin.tie(0)->sync_with_stdio(0); int t;cin >> t; while(t--) { cin >> n; g = vector<vector<int>>(n+1); nxt = vector<int>(n+1, -1); for(int f, t, i = 1; i < n; i++) { cin >> f >> t; g[f].push_back(t); g[t].push_back(f); } n = dfs(1, 0, 0)[0]; do { cout << n << " "; } while((n=nxt[n])!=-1); 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 |
---|
1 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 ... 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 99 82 81 59 5 71 55 17 24 13... Truncated |