#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long
#define int long long
// #define int unsigned long long
const ll inf = 1e9 + 7;
const ll weirdMod = 998244353;
vector<pair<int, pii>> G[200005];
int n, q, val[200005], ans[200005];
void temp_dfs(int v, int par) {
for (auto u : G[v]) {
if (u.ff == par) continue;
val[1] += u.sc.sc;
temp_dfs(u.ff, v);
}
}
void reroot_dfs(int v, int par) {
for (auto u : G[v]) {
if (u.ff == par) continue;
val[u.ff] = val[v] - u.sc.sc + u.sc.ff;
reroot_dfs(u.ff, v);
}
}
void solve() {
cin >> n;
int sum = 0;
for (int i = 1; i < n; i++) {
int a, b, x, y;
cin >> a >> b >> x >> y;
G[a].pb({b, {x, y}});
G[b].pb({a, {y, x}});
sum += x + y;
} temp_dfs(1, 0); reroot_dfs(1, 0);
cin >> q >> q;
int mx = 0;
for (int i = 1; i <= n; i++) {
mx = max(mx, val[i]);
} cout << sum - mx;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8028 KB |
Output is correct |
2 |
Correct |
111 ms |
27504 KB |
Output is correct |
3 |
Correct |
130 ms |
35088 KB |
Output is correct |
4 |
Correct |
124 ms |
25940 KB |
Output is correct |
5 |
Correct |
104 ms |
27332 KB |
Output is correct |
6 |
Correct |
107 ms |
28716 KB |
Output is correct |
7 |
Correct |
92 ms |
26372 KB |
Output is correct |
8 |
Correct |
147 ms |
35412 KB |
Output is correct |
9 |
Correct |
74 ms |
26356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8028 KB |
Output is correct |
2 |
Correct |
111 ms |
27504 KB |
Output is correct |
3 |
Correct |
130 ms |
35088 KB |
Output is correct |
4 |
Correct |
124 ms |
25940 KB |
Output is correct |
5 |
Correct |
104 ms |
27332 KB |
Output is correct |
6 |
Correct |
107 ms |
28716 KB |
Output is correct |
7 |
Correct |
92 ms |
26372 KB |
Output is correct |
8 |
Correct |
147 ms |
35412 KB |
Output is correct |
9 |
Correct |
74 ms |
26356 KB |
Output is correct |
10 |
Incorrect |
2 ms |
8028 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |