/*****************/
/* [ ] Subtask 1 */
/* [o] Subtask 2 */
/* [ ] Subtask 3 */
/* [ ] Subtask 4 */
/* [ ] Subtask 5 */
/* [ ] Subtask 6 */
/*****************/
#include <bits/stdc++.h>
using namespace std;
#define Foxyy cin.tie(0); cout.sync_with_stdio(0);
#define ll long long
const ll LINF = 1e18;
struct Solver {
int n;
vector<map<int, int>>& adj;
int q;
ll getAns0(int u, int p) {
ll ret = 0;
for (auto [v, w] : adj[u]) if (v != p) {
ret = ret + w + getAns0(v, u);
}
return ret;
}
void getAns(ll& ans, ll cur, int u, int p) {
ans = min(ans, cur);
for (auto [v, w] : adj[u]) if (v != p) {
getAns(ans, cur - w + adj[v][u], v, u);
}
}
void solve() {
ll ans0 = getAns0(0, -1);
ll ans = LINF;
getAns(ans, ans0, 0, -1);
cout << ans << '\n';
}
};
signed main() {
Foxyy
int T = 1;
// cin >> T;
while (T--) {
int n;
cin >> n;
vector<map<int, int>> adj(n);
for (int i = 0; i < n-1; i++) {
int a, b, c, d;
cin >> a >> b >> c >> d;
a--, b--;
adj[a][b] = c;
adj[b][a] = d;
}
int q;
cin >> q;
Solver solver{n, adj, q};
solver.solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
268 ms |
34756 KB |
Output is correct |
3 |
Correct |
307 ms |
41304 KB |
Output is correct |
4 |
Correct |
250 ms |
33508 KB |
Output is correct |
5 |
Correct |
271 ms |
34788 KB |
Output is correct |
6 |
Correct |
271 ms |
35740 KB |
Output is correct |
7 |
Correct |
281 ms |
34892 KB |
Output is correct |
8 |
Correct |
310 ms |
41504 KB |
Output is correct |
9 |
Correct |
293 ms |
34960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
268 ms |
34756 KB |
Output is correct |
3 |
Correct |
307 ms |
41304 KB |
Output is correct |
4 |
Correct |
250 ms |
33508 KB |
Output is correct |
5 |
Correct |
271 ms |
34788 KB |
Output is correct |
6 |
Correct |
271 ms |
35740 KB |
Output is correct |
7 |
Correct |
281 ms |
34892 KB |
Output is correct |
8 |
Correct |
310 ms |
41504 KB |
Output is correct |
9 |
Correct |
293 ms |
34960 KB |
Output is correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |