#include<bits/stdc++.h>
using namespace std;
#define int long long
const int inf=1e9+7;
int n,q;
template <typename T>
bool minimize(T &a,T b)
{
if(a>b)
{
a=b;
return true;
}
return false;
}
struct edge
{
int x,value_x,value_y;
edge(int _x=0,int _value_x=0,int _value_y=0)
{
x=_x,value_x=_value_x,value_y=_value_y;
}
};
vector<vector<edge> >a;
struct SUB1
{
int n;
vector<vector<int> >dp;
SUB1(int _n=0)
{
n=_n;
dp.resize(n+7,vector<int>(2));
}
void dfs(int x,int par)
{
dp[x][0]=0;
dp[x][1]=inf;
for(edge need:a[x])
{
int node=need.x;
int value_x=need.value_x;
int value_y=need.value_y;
if(node==par)continue;
dfs(node,x);
dp[x][1]=dp[x][1]+dp[node][0]+value_x;
minimize(dp[x][1],dp[node][1]+dp[x][0]+value_y);
dp[x][0]+=dp[node][0]+value_x;
}
minimize(dp[x][1],dp[x][0]);
}
void calc()
{
dfs(1,0);
cout<<dp[1][1];
}
};
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
a.resize(n+7);
for(int i=1;i<=n-1;i++)
{
int x,y,value_x,value_y;
cin>>x>>y>>value_x>>value_y;
a[x].push_back({y,value_x,value_y});
a[y].push_back({x,value_y,value_x});
}
int q;
cin>>q;
if(q==1)
{
int x;
cin>>x;
if(x==1)
{
SUB1 s(n);
s.calc();
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
188 ms |
34924 KB |
Output is correct |
3 |
Correct |
163 ms |
44408 KB |
Output is correct |
4 |
Correct |
140 ms |
34060 KB |
Output is correct |
5 |
Correct |
150 ms |
34952 KB |
Output is correct |
6 |
Correct |
172 ms |
36772 KB |
Output is correct |
7 |
Correct |
131 ms |
34204 KB |
Output is correct |
8 |
Correct |
196 ms |
44784 KB |
Output is correct |
9 |
Correct |
104 ms |
33400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
188 ms |
34924 KB |
Output is correct |
3 |
Correct |
163 ms |
44408 KB |
Output is correct |
4 |
Correct |
140 ms |
34060 KB |
Output is correct |
5 |
Correct |
150 ms |
34952 KB |
Output is correct |
6 |
Correct |
172 ms |
36772 KB |
Output is correct |
7 |
Correct |
131 ms |
34204 KB |
Output is correct |
8 |
Correct |
196 ms |
44784 KB |
Output is correct |
9 |
Correct |
104 ms |
33400 KB |
Output is correct |
10 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |