#include <bits/stdc++.h>
using namespace std;
struct edge {
int u, v, c, d;
int other( int p ) {
return u ^ v ^ p;
}
int cost( int p ) {
if ( p == u )
return d;
return c;
}
};
const int MAX_N = 2e5;
int parent[MAX_N + 1];
long long cost[MAX_N + 1], parentEdgeCost[MAX_N + 1];
long long sumCost;
edge edges[MAX_N];
vector<int> adj[MAX_N + 1];
void dfs( int u, int p ) {
for ( int e: adj[u] ) {
int v = edges[e].other( u ), c = edges[e].cost( u ), d = (edges[e].c ^ edges[e].d ^ c);
if ( v == p )
continue;
parent[v] = u;
cost[v] = cost[u] + d;
sumCost += c;
dfs( v, u );
}
}
int main() {
int n;
long long sumTotal = 0;
cin >> n;
for ( int i = 0; i < n - 1; i++ ) {
int u, v, c, d;
cin >> u >> v >> c >> d;
edges[i] = { u, v, c, d };
adj[u].push_back( i );
adj[v].push_back( i );
sumTotal += c + d;
}
int q, e;
cin >> q >> e;
sumCost = 0;
dfs( 1, 0 );
int r = 1;
for ( int v = 2; v <= n; v++ ) {
if ( cost[v] > cost[r] )
r = v;
}
sumCost = 0;
cost[r] = 0;
dfs( r, 0 );
int maxx = 0;
for ( int v = 1; v <= n; v++ ) {
if ( cost[v] > maxx )
maxx = cost[v];
}
cout << sumTotal - (sumCost + maxx);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Incorrect |
275 ms |
24064 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |