CSES - Datatähti Open 2021 - Results
Submission details
Task:Distances
Sender:pwild
Submission time:2021-01-30 14:35:54 +0200
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.01 s1, 2details
#20.01 s2details

Code

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

vl adj[111];

vl rec(ll i, ll p) {
	vvl a;
	for (ll j: adj[i]) if (j != p) {
		a.pb(rec(j,i));
	}
	if (sz(a)) reverse(all(a.back()));
	
	vl res = {i};
	for (vl v: a) copy(all(v), back_inserter(res));
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll tc; cin >> tc;
	while (tc--) {
		ll n; cin >> n;
		FOR(i,1,n+1) adj[i].clear();
		
		FOR(i,1,n) {
			ll a, b;
			cin >> a >> b;
			adj[a].pb(b);
			adj[b].pb(a);
		}

		vl res = rec(1,0);
		for (ll a: res) cout << a << " ";
		cout << endl;
	}
}

Test details

Test 1

Group: 1, 2

Verdict:

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 8 7 6 5 2 3 4 
1 3 8 2 7 4 6 5 
1 4 6 5 7 2 8 3 
1 6 8 3 2 4 7 5 
1 6 4 7 5 2 3 8 
...
Truncated

Test 2

Group: 2

Verdict:

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 22 60 19 93 47 11 12 68 78 2...
Truncated