#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define N 200005
#define mp make_pair
using namespace std;
ll n,ch[N],ans[N],al;
vector<pair<ll,pair<ll,ll> > >g[N];
vector<pair<pair<ll,ll> , pair<ll,ll> > > ed;
void calc1(ll x,ll par){
for(int i=0; i<g[x].size(); i++)
if(g[x][i].f != par){
calc1(g[x][i].f , x);
ch[x] += g[x][i].s.s + ch[g[x][i].f];
}
}
void solve1(ll x,ll par,ll zed){
ans[1] = max(ans[1] , zed + ch[x]);
for(int i=0; i<g[x].size(); i++)
if(g[x][i].f != par)
solve1(g[x][i].f , x , zed + ch[x] - g[x][i].s.s + g[x][i].s.f);
}
int main(){
ios::sync_with_stdio(false);
cin >> n;
for(int i=1; i<n; i++){
ll a,b,c,d;
cin >> a >> b >> c >> d;
al += c + d;
g[a].pb(mp(b , mp(c , d)));
g[b].pb(mp(a , mp(d , c)));
ed.pb(mp(mp(a , b) , mp(c , d)));
}
calc1(1 , 0);
solve1(1 , 0 , 0);
cout << al - ans[1] << '\n';
return 0;
}
Compilation message
designated_cities.cpp: In function 'void calc1(long long int, long long int)':
designated_cities.cpp:13:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<g[x].size(); i++)
~^~~~~~~~~~~~
designated_cities.cpp: In function 'void solve1(long long int, long long int, long long int)':
designated_cities.cpp:21:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<g[x].size(); i++)
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
4984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
5112 KB |
Output is correct |
2 |
Incorrect |
285 ms |
25936 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
4984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
5112 KB |
Output is correct |
2 |
Incorrect |
285 ms |
25936 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
4984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |