#include<iostream>
#include<vector>
using namespace std;
int maxDuctLength(vector<int>fromJunction,vector<int>toJunction,vector<int>ductLength,int ductNumber)
{
int result=0;
for(size_t i=0;i<fromJunction.size();++i)
{
if(ductNumber==fromJunction[i])
result=max(result,ductLength[i]+maxDuctLength(fromJunction,toJunction,ductLength,toJunction[i]));
}
return result;
}
int estimateTimeOut(vector<int>fromJunction,vector<int>toJunction,vector<int>ductLength)
{
int result=-maxDuctLength(fromJunction,toJunction,ductLength,0);
for(size_t i=0;i<ductLength.size();++i)
{
result+=2*ductLength[i];
}
return result;
}
int main()
{
int a[]={0,0,0,1,4,4,6,7,7,7,20};
vector<int> fromJunction(a,a+sizeof(a)/sizeof(int));
int b[]={1,3,4,2,5,6,7,20,9,10,31};
vector<int> toJunction(b,b+sizeof(b)/sizeof(int));
int c[]={10,10,100,10,5,1,1,100,1,1,5};
vector<int> ductLength(c,c+sizeof(c)/sizeof(int));
cout<<estimateTimeOut(fromJunction,toJunction,ductLength)<<endl;
return 0;
}
#include<vector>
using namespace std;
int maxDuctLength(vector<int>fromJunction,vector<int>toJunction,vector<int>ductLength,int ductNumber)
{
int result=0;
for(size_t i=0;i<fromJunction.size();++i)
{
if(ductNumber==fromJunction[i])
result=max(result,ductLength[i]+maxDuctLength(fromJunction,toJunction,ductLength,toJunction[i]));
}
return result;
}
int estimateTimeOut(vector<int>fromJunction,vector<int>toJunction,vector<int>ductLength)
{
int result=-maxDuctLength(fromJunction,toJunction,ductLength,0);
for(size_t i=0;i<ductLength.size();++i)
{
result+=2*ductLength[i];
}
return result;
}
int main()
{
int a[]={0,0,0,1,4,4,6,7,7,7,20};
vector<int> fromJunction(a,a+sizeof(a)/sizeof(int));
int b[]={1,3,4,2,5,6,7,20,9,10,31};
vector<int> toJunction(b,b+sizeof(b)/sizeof(int));
int c[]={10,10,100,10,5,1,1,100,1,1,5};
vector<int> ductLength(c,c+sizeof(c)/sizeof(int));
cout<<estimateTimeOut(fromJunction,toJunction,ductLength)<<endl;
return 0;
}