#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define MAX 200000
struct x {
lli des;
lli w;
lli comp;
};
lli n,a,b,c,d,raiz,op,total,q;
vector<x> hijos[MAX+2];
lli sub[MAX+2];
void pre_dfs(lli pos, lli padre) {
for(auto h : hijos[pos]) {
if(h.des == padre) continue;
pre_dfs(h.des,pos);
sub[pos] += sub[h.des] + (h.comp-h.des);
}
}
void busca_raiz(lli pos, lli padre,lli carga) {
lli a = carga + sub[pos];
if (a > op){
op = a;
raiz = pos;
}
for(auto h : hijos[pos]){
if(h.des == padre) continue;
a = carga + sub[pos] - sub[h.des];
a -= (h.comp-h.w);
a += h.w;
busca_raiz(h.des,pos,a);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
rep(i,1,n-1) {
cin >> a >> b >> c >> d;
hijos[a].push_back({b,c,c+d});
hijos[b].push_back({a,d,c+d});
total += (c+d);
}
pre_dfs(1,0);
busca_raiz(1,0,0);
cin >> q >> a;
cout << (total-op);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
5028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
5024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
5028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |