답안 #882966

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882966 2023-12-04T09:29:14 Z tsumondai Travelling Trader (CCO23_day2problem2) C++14
0 / 25
7 ms 25192 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 1e6 + 5;

const int oo = 1e9, mod = 1e9 + 7;

int n, m, k, a[N];
vector<int> edges[N];

vector<int> res;
void dfs(int u, int par) {
	res.push_back(u);
	for (int v : edges[u]) {
		if (v == par) continue;
		for (int w : edges[v]) {
			if (w == u) continue;
			dfs(w, v);
		}
		res.push_back(v);
	}
}
void process() {
	int total = 0;
	for (int i = 1; i <= n; i++) total += a[i];
	dfs(1, 0);
	cout << total << '\n';
	cout << n << '\n';
	for (int v : res) cout << v << (v == res.back() ? '\n' : ' ');
}

signed main() {
	cin.tie(0)->sync_with_stdio(false);
	//freopen(".inp", "r", stdin);
	//freopen(".out", "w", stdout);
	cin >> n >> k;
	foru(i, 1, n - 1) {
		int u, v; cin >> u >> v;
		edges[u].pb(v);
		edges[v].pb(u);
	}
	foru(i, 1, n) cin >> a[i];
	process();
	cerr << "Time elapsed: " << __TIME << " s.\n";
	return 0;
}

// dont stop
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 25180 KB Output is correct
2 Incorrect 6 ms 25180 KB x_1 and x_2 are too far apart
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 25180 KB Output is correct
2 Incorrect 5 ms 25192 KB x_7 and x_8 are too far apart
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 25180 KB Output is correct
2 Incorrect 5 ms 25192 KB x_7 and x_8 are too far apart
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 25180 KB Output is correct
2 Incorrect 5 ms 25192 KB x_7 and x_8 are too far apart
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 25180 KB total profit is not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 25180 KB total profit is not correct
2 Halted 0 ms 0 KB -