Submission #24868517


Source Code Expand

#include <bits/stdc++.h>
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("tune=native")*/
using namespace std;
typedef long long ll;
typedef long double ld;

const int MAX_N = 200005;

int n;
vector<int> g[MAX_N];
vector<int> order;

void dfs(int u, int p = -1)
{
	order.push_back(u);
	for (int v : g[u])
		if (v != p)
		{
			dfs(v, u);
			order.push_back(u);
		}
}

int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> n;
	for (int i = 0; i < n - 1; i++)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	for (int i = 0; i < n; i++)
		sort(g[i].begin(), g[i].end());

	dfs(0);

	for (int x : order)
		cout << (x + 1) << ' ';
	cout << '\n';

	return 0;
}

Submission Info

Submission Time
Task D - Takahashi Tour
User artsin6
Language C++ (GCC 9.2.1)
Score 400
Code Size 814 Byte
Status AC
Exec Time 127 ms
Memory 28852 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 17
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All hand_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
hand_01.txt AC 11 ms 8268 KiB
random_01.txt AC 79 ms 14348 KiB
random_02.txt AC 108 ms 16332 KiB
random_03.txt AC 20 ms 8892 KiB
random_04.txt AC 108 ms 16392 KiB
random_05.txt AC 25 ms 9312 KiB
random_06.txt AC 111 ms 16400 KiB
random_07.txt AC 127 ms 27512 KiB
random_08.txt AC 124 ms 28852 KiB
random_09.txt AC 107 ms 16248 KiB
random_10.txt AC 114 ms 16196 KiB
random_11.txt AC 95 ms 16884 KiB
random_12.txt AC 93 ms 16916 KiB
random_13.txt AC 113 ms 16840 KiB
random_14.txt AC 103 ms 16972 KiB
sample_01.txt AC 10 ms 8256 KiB
sample_02.txt AC 8 ms 8224 KiB