| Task: | Distances |
| Sender: | Nagibator228 |
| Submission time: | 2021-01-31 13:49:45 +0200 |
| Language: | C++ (C++11) |
| 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 'int main()':
input/code.cpp:95:13: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
dfs1(v, v);
~~~~^~~~~~Code
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize ("trapv")
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,avx,sse4.1,sse4.2,mmx")
typedef long long ll;
#define ff first
#define what(x) cerr << #x << " = " << x << '\n'
#define ss second
#define pb push_back
#define ld long double
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD 1000000007
using namespace std;
mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r){
return mt_rnd_64() % (r - l + 1) + l;
}
using namespace __gnu_pbds;
template<class T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T>
using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll N = 200 + 10;
const ll inf = 1e18 + 10;
vector <ll> g[N];
ll d[N];
void dfs(ll v, ll p, ll cnt)
{
d[v] = cnt;
for (auto to : g[v])
{
if (to != p)
{
dfs(to, v, cnt + 1);
}
}
}
void dfs1(ll v, ll p)
{
cout << v << ' ';
for (auto to : g[v])
{
if (to != p)
{
dfs1(to, v);
}
}
}
signed main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ll q;
cin >> q;
while (q--)
{
ll n;
cin >> n;
for (ll i = 1; i <= n; ++i) g[i].clear();
for (ll i = 1; i < n; ++i)
{
ll x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
dfs(1, 1, 0);
ll mx = -inf;
ll v;
for (ll i = 1; i <= n; ++i)
{
if (d[i] > mx)
{
mx = d[i];
v = i;
}
}
dfs1(v, v);
cout << '\n';
}
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 |
|---|
| 5 2 3 7 8 4 1 6 2 8 7 3 1 5 6 4 7 2 8 6 3 1 4 5 3 8 6 2 4 1 5 7 5 2 7 3 4 8 1 6 ... 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 |
|---|
| 92 43 94 80 97 85 54 89 61 42 ... Truncated |
