#include<bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define ll long long
const int MAXN=10101;
ll ans=INF,res;
struct edge{
int l,r,b;
}e[MAXN<<1];
ll n,wei[MAXN];
bool ok[MAXN]={false};
void dfs(int cnt, int point){
if(point==0||ok[point]) return;
res+=(cnt*wei[point]);
ok[point]=true;
dfs(cnt+1, e[point].l);
dfs(cnt+1, e[point].r);
dfs(cnt+1, e[point].b);
ok[point]=false;
}
int main(){
cin>>n;
for(int i=1; i<=n; i++){
int u,w,v;
cin>>w>>u>>v;
e[i].l=u, e[i].r=v;
e[u].b=i, e[v].b=i;
wei[i]=w;
}
for(int i=1; i<=n; i++){
res=0;
dfs(0, i);
ans=min(res, ans);
}
cout<<ans;
}