CSES - Datatähti Open 2021 - Results
Submission details
Task:Distances
Sender:dynam1c
Submission time:2021-01-30 17:25:08 +0200
Language:C++17
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED29
#2ACCEPTED71
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s2details

Code

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define endl "\n"
#define all(c) (c).begin(),(c).end()

// if you're reading this i hope to meet you in IOI 2021
// RECHECK CONSTRAINTS AFTER MAKING A REDUCTION

void solve() {
	int n;
	cin >> n;
	vector<vector<int>> graph(n);
	for (int i = 0; i < n-1; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	vector<int> res;
	function<void(int, int, bool)> dfs = [&](int v, int p, bool b) { // if b you end on root, if not you end one below root
		if (!b) res.push_back(v);
		for (int ne : graph[v]) if (ne != p) dfs(ne, v, !b);
		if (b) res.push_back(v);
	};
	dfs(0, 0, true);
	for (int e : res) cout << e+1 << " ";
	cout << endl;
}

signed main() {
	// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) solve();
}
/* --- PSolving ---
 * Simplifying (getting rid of variables, conditions, code logic, etc.)
 * Reframing
 * Solving a subtask (subgoal, aux. problem, removing a condition or fixing a parameter, etc.)
 * Inducing
 * Divide and conquer
 * Working backwards
 * Visual intuition
 * !! Reductions don't have to be specializations, they can be generalizations
 */

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...