# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
996427 | otarius | Designated Cities (JOI19_designated_cities) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
int q, q; cin >> q >> q;
int mx = 0;
for (int i = 1; i <= n; i++) {
mx = max(mx, val[i]);
} cout << cost - 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;
}