/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int n;
vi co;
vvi G;
class Cent{
	public:
	int n;
	vi co,cent;
	vvi G;
	Cent(int size){
		n=size;
		G=vvi(n);
	}
	void add_edge(int a,int b){
		G[a].pb(b);
		G[b].pb(a);
	}
	void dfs(int u,int prev){
		co[u]=1;
		bool is_cent=true;
		for(auto v:G[u])if(v!=prev){
			dfs(v,u);
			co[u]+=co[v];
			if(co[v]>n/2)is_cent=false;
		}
		if(n-co[u]>n/2)is_cent=false;
		if(is_cent)cent.pb(u);
	}
	vi center(){
		co=vi(n);
		cent=vi();
		dfs(0,-1);
		return cent;
	}
};
signed main(){
	cin>>n;
	Cent ce(n);
	vvi in;
	rep(i,n-1){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		ce.add_edge(a,b);
		in.pb({a,b,c});
	}
	vi cent=ce.center(),co=ce.co;
	cent.pb(n);
	int sum=0,mi=inf,h=false;
	FOR(a,in){
		int t=min(co[a[0]],co[a[1]]);
		t=min(t,n-t)*2;
		bool h1=a[0]==cent[0]||a[0]==cent[1];
		bool h2=a[1]==cent[0]||a[1]==cent[1];
		if(h1&&h2)h=true,t--;
		if(h1||h2)cmin(mi,a[2]);
		sum+=a[2]*t;
	}
	if(!h&&mi-inf)sum-=mi;
	cout<<sum<<endl;
}















Measured memory_bytes: 16560