CSES - Datatähti Open 2021 - Results
Submission details
Task:Distances
Sender:nhho
Submission time:2021-01-31 08:06:41 +0200
Language:C++ (C++11)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED29
#2ACCEPTED71
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s2details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:31:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < ans.size(); i++) printf("%d%c", ans[i], " \n"[i == ans.size() - 1]);
                   ~~^~~~~~~~~~~~
input/code.cpp:31:71: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < ans.size(); i++) printf("%d%c", ans[i], " \n"[i == ans.size() - 1]);
                                                                     ~~^~~~~~~~~~~~~~~~~
input/code.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &t);
  ~~~~~^~~~~~~~~~
input/code.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
input/code.cpp:24:9: warning: ignoring return value of 'int sca...

Code

#include <bits/stdc++.h>

using namespace std;

int t, n;
vector<int> v[105];
vector<int> ans;

void dfs(int a, bool b, int c) {
	if (b) ans.push_back(a);
	b ^= 1;
	for (int i : v[a])
		if (i != c)
			dfs(i, b, a);
	if (b) ans.push_back(a);
}

int main() {
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		for (int i = 1; i < n; i++) {
			int ta, tb;
			scanf("%d%d", &ta, &tb);
			v[ta].push_back(tb);
			v[tb].push_back(ta);
		}
		ans.clear();
		dfs(1, 0, 0);
		for (int i = 1; i <= n; i++) vector<int>().swap(v[i]);
		for (int i = 0; i < ans.size(); i++) printf("%d%c", ans[i], " \n"[i == ans.size() - 1]);
	}
}

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

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