#include <bits/stdc++.h>
#define maxn 200005
#define INF (long long)1e18
#define pii pair<int,int>
#define sus first
#define w second
using namespace std;
/*** 20:50***/
int n;
vector<pii>adj[maxn];
long long dp[maxn];
long long down[maxn],up[maxn];
void dfs(int v,int p,int tez)
{
down[v]=0LL;
for(auto x:adj[v])
{
if(x.sus!=p)
{
down[v]+=x.w;
dfs(x.sus,v,x.w);
down[v]+=down[x.sus];
}
}
up[v]=0LL;
for(auto x:adj[v])
{
if(x.sus==p)
{
up[v]+=up[p];
up[v]+=x.w;
up[v]+=down[p]-tez-down[v];
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n;
long long SUM=0LL;
for(int i=1;i<n;i++)
{
int a,b,c,d;
cin>>a>>b>>c>>d;
adj[a].push_back({b,c});
adj[b].push_back({a,d});
SUM+=c+d;
}
dfs(1,1,0);
dp[1]=0LL;
for(int i=1;i<=n;i++)
{
dp[1]=max(dp[1],up[i]+down[i]);
}
int q;
cin>>q;
while(q>0)
{
int e;
cin>>e;
cout<<SUM-dp[e]<<endl;
q--;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Incorrect |
209 ms |
21852 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
4984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Incorrect |
209 ms |
21852 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |