#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=200005;
const int INF=1e18;
int n;
vector<pair<int,int>> adj[N];
vector<int> v(N);
void dfs1(int k,int pa){
for(auto [j,c]:adj[k]){
if(j==pa)continue;
v[1]+=c;
dfs1(j,k);
}
}
void dfs2(int k,int pa,int now){
for(auto [j,c]:adj[k]){
if(j==pa){
v[k]=now+c;
}
}
for(auto [j,c]:adj[k]){
if(j==pa){
continue;
}
dfs2(j,k,v[k]-c);
}
}
int32_t main() {
LCBorz;
int n;cin>>n;
int total=0;
for(int i=1;i<n;i++){
int a,b,c,d;cin>>a>>b>>c>>d;
adj[a].push_back({b,d});
adj[b].push_back({a,c});
total+=c+d;
}
dfs1(1,1);
dfs2(1,1,v[1]);
int mx=*max_element(all(v));
cout<<total-mx<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
110 ms |
16720 KB |
Output is correct |
3 |
Correct |
155 ms |
30992 KB |
Output is correct |
4 |
Correct |
110 ms |
21844 KB |
Output is correct |
5 |
Correct |
125 ms |
23240 KB |
Output is correct |
6 |
Correct |
129 ms |
24520 KB |
Output is correct |
7 |
Correct |
101 ms |
22696 KB |
Output is correct |
8 |
Correct |
157 ms |
31248 KB |
Output is correct |
9 |
Correct |
78 ms |
22460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
110 ms |
16720 KB |
Output is correct |
3 |
Correct |
155 ms |
30992 KB |
Output is correct |
4 |
Correct |
110 ms |
21844 KB |
Output is correct |
5 |
Correct |
125 ms |
23240 KB |
Output is correct |
6 |
Correct |
129 ms |
24520 KB |
Output is correct |
7 |
Correct |
101 ms |
22696 KB |
Output is correct |
8 |
Correct |
157 ms |
31248 KB |
Output is correct |
9 |
Correct |
78 ms |
22460 KB |
Output is correct |
10 |
Incorrect |
2 ms |
6492 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |