ABC 361
Table of Contents
https://atcoder.jp/contests/abc361
A. Insert
https://atcoder.jp/contests/abc361/tasks/abc361_a
B. Intersection of Cuboids
https://atcoder.jp/contests/abc361/tasks/abc361_b
C. Make Them Narrow
https://atcoder.jp/contests/abc361/tasks/abc361_c
D. Go Stone Puzzle
https://atcoder.jp/contests/abc361/tasks/abc361_d
E. Tree and Hamilton Path 2
https://atcoder.jp/contests/abc361/tasks/abc361_e
解説 AC
void solve() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<vector<pair<ll, ll>>> graph(N);
vll C;
rep(i, N - 1) {
int a, b, c;
cin >> a >> b >> c;
a--, b--;
C.push_back(c);
graph[a].push_back({b, c});
graph[b].push_back({a, c});
}
vll dist(N);
auto dfs = [&](auto dfs, int now, int p) -> void {
for (auto [nx, c] : graph[now]) {
if (nx == p) continue;
dist[nx] = dist[now] + c;
dfs(dfs, nx, now);
}
};
dfs(dfs, 0, -1);
int s = -1;
ll d = -1;
rep(i, N) {
if (d < dist[i]) {
d = dist[i];
s = i;
}
}
rep(i, N) dist[i] = 0;
dfs(dfs, s, -1);
d = -1;
rep(i, N) {
if (d < dist[i]) {
d = dist[i];
}
}
ll ans = accumulate(all(C), 0ll);
ans *= 2;
ans -= d;
cout << ans << endl;
}
F. x = a^b
https://atcoder.jp/contests/abc361/tasks/abc361_f