제출 #882966

#제출 시각아이디문제언어결과실행 시간메모리
882966tsumondaiTravelling Trader (CCO23_day2problem2)C++14
0 / 25
7 ms25192 KiB
#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
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...