1 solutions
-
0
C++ :
#include <algorithm> #include <cstdio> #include <vector> using namespace std; const int N = 1e5 + 5; int n; vector<vector<pair<int, int>>> e; long long s, mx; void dfs(int u, int f, long long d) { mx = max(mx, d); for (auto p : e[u]) { if (p.first != f) dfs(p.first, u, d + p.second); } } int main() { scanf("%d", &n); e.resize(n + 1); for (int i = 1; i < n; i++) { int u, v, w; scanf("%d%d%d", &u, &v, &w); e[u].emplace_back(make_pair(v, w)); e[v].emplace_back(make_pair(u, w)); s += w; } dfs(1, 0, 0); printf("%lld\n", s * 2 - mx); return 0; }
- 1
Information
- ID
- 123
- Time
- 1000ms
- Memory
- 512MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By