CSES - Datatähti 2021 loppu - Results
Submission details
Task:Etäisyydet
Sender:intoo
Submission time:2021-01-23 17:39:02 +0200
Language:C++17
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED29
#2ACCEPTED71
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s2details

Code

#include <iostream>
#include <vector>

using namespace std;

int t;
vector<int> v[101][101], o[101];

void dfs(int x, int p, int e) {
	if (e % 2) {
		o[t].push_back(x);
		for (int y : v[t][x])
			if (y != p) dfs(y, x, e+1);
	} else {
		for (int y : v[t][x])
			if (y != p) dfs(y, x, e+1);
		o[t].push_back(x);
	}
}

int main() {
	cin >> t;
	while (t --> 0) {
		int n;
		cin >> n;
		for (int i = 1; i < n; ++i) {
			int a, b;
			cin >> a >> b;
			v[t][a].push_back(b);
			v[t][b].push_back(a);
		}
		dfs(1, 0, 0);
		for (auto x : o[t]) cout << x << ' ';
		cout << endl;
	}
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

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

Test 2

Group: 2

Verdict: ACCEPTED

input
100
100
37 59
81 37
44 81
...

correct output
1 99 82 81 59 5 71 55 17 24 13...

user output
22 60 44 37 17 5 55 71 59 24 3...