#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <tuple>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define piii pair<int, pii>
#define plll pair<long long, pll>
#define tiii tuple<int, int, int>
#define tiiii tuple<int, int, int, int>
#define tlll tuple<long long, long long, long long>
#define tllll tuple<long long, long long, long long, long long>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
#define DEBUG
using namespace std;
vector<tiii> gph[202020];
long long mx;
long long sz[202020];
void dfs(int x, int p)
{
for(auto [y, a, b] : gph[x]) if(y != p) dfs(y, x), sz[x] += b + sz[y];
}
void dfs2(int x, int p, long long d)
{
mx = max(mx, d);
for(auto [y, a, b] : gph[x]) if(y != p) dfs2(y, x, d + a - b);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
long long ans = 0;
for(int i = 1; i < n; ++i)
{
int x, y, a, b; cin >> x >> y >> a >> b; --x; --y;
gph[x].push_back({y, a, b});
gph[y].push_back({x, b, a});
ans += a, ans += b;
}
dfs(0, -1);
dfs2(0, -1, sz[0]);
// cout << sz[0] << endl;
int T; cin >> T;
while(T--)
{
int x; cin >> x;
cout << ans - mx;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
5100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
255 ms |
21356 KB |
Output is correct |
3 |
Correct |
328 ms |
32108 KB |
Output is correct |
4 |
Correct |
236 ms |
19948 KB |
Output is correct |
5 |
Correct |
232 ms |
21156 KB |
Output is correct |
6 |
Correct |
249 ms |
23020 KB |
Output is correct |
7 |
Correct |
200 ms |
21136 KB |
Output is correct |
8 |
Correct |
286 ms |
32620 KB |
Output is correct |
9 |
Correct |
150 ms |
20252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
5100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
5100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
255 ms |
21356 KB |
Output is correct |
3 |
Correct |
328 ms |
32108 KB |
Output is correct |
4 |
Correct |
236 ms |
19948 KB |
Output is correct |
5 |
Correct |
232 ms |
21156 KB |
Output is correct |
6 |
Correct |
249 ms |
23020 KB |
Output is correct |
7 |
Correct |
200 ms |
21136 KB |
Output is correct |
8 |
Correct |
286 ms |
32620 KB |
Output is correct |
9 |
Correct |
150 ms |
20252 KB |
Output is correct |
10 |
Incorrect |
4 ms |
5100 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
5100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |