#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class TreeSize{
public:
  Int V;
  Int root;
  vector<vector<Int> > G;
  vector<Int> w;
  vector<Int> sz;
  Int ok;
  TreeSize():V(-1){};
  TreeSize(Int V,Int root = 0):V(V),root(root),G(V),w(V,1),sz(V,0),ok(0){}
  TreeSize(vector<vector<Int> > G,Int root = 0):V(G.size()),root(root),G(G),w(V,1),sz(V,0),ok(0){}
  void resize(Int n){*this = TreeSize(n);}
  Int& operator [](Int i){return w[i];}
  
  void add_edge(Int a,Int b){
    ok = false;
    assert(a < V && b < V);
    assert(a >= 0 && b >= 0);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  void build(Int root=-1){
    ok = 1;
    if(root != -1) this->root = root;
    dfs(this->root,-1);
  }
  
  Int dfs(Int pos,Int pre = -1){
    sz[pos] = w[pos];
    for(Int to:G[pos]) if(to != pre) sz[pos] += dfs(to, pos);
    return sz[pos];
  }
  Int size(Int i){assert(ok);return sz[i];}
};

class TreeG{
public:
  Int V;
  vector<vector<Int> > G;
  vector<Int> par;
  TreeG():V(-1){};
  TreeG(Int V):V(V),G(V),par(V){}
  
  void add_edge(Int a,Int b){
    assert(a < V && b < V);
    assert(a >= 0 && b >= 0);
    G[a].push_back(b);
    G[b].push_back(a);
  }

  Int dfs(Int pos,Int pre){
    par[pos] = pre;
    Int res = 1;
    for(Int to: G[pos]) if(to != pre) res += dfs(to, pos); 
    return res;
  }
  
  //rootから連結するグラフの重心を求める
  vector<Int> get(Int root = 0){ 
    TreeSize sz(G);
    sz.build(root);
    par.resize(V,-2);
    Int size = dfs(root,-1);
    
    vector<Int> res;
    for(Int i=0;i<V;i++){
      if(par[i] == -2) continue;
      Int flag = (size - sz.size(i)) <= size/2;
      for(Int to:G[i]) if(to != par[i]) flag &= (sz.size(to) <= size/2);
      if(flag) res.push_back(i);  
    }
    assert(!res.empty() && res.size() < 3);
    return res;
  }

  //fromからtoへのエッジ及び、fromを親とした時のtoを根とする部分木を削除
  void erase(Int from,Int to){
    G[from].erase(find(G[from].begin(),G[from].end(), to));
    function<void(Int,Int)> dfs=[&](Int pos,Int pre){
      for(Int to:G[pos]) if(to != pre) dfs(to, pos);
      G[pos].clear();
    };
    dfs(to, from);
  }
};


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int n;
  cin>>n;

  TreeG TG(n);
  TreeSize TS(n);
  vector<T> E;
  for(Int i=0;i<n-1;i++){
    Int a, b, c;
    cin>>a>>b>>c; a--, b--;
    TG.add_edge(a, b);
    TS.add_edge(a, b);
    E.push_back(T(a, b, c));
  }

  auto g = TG.get(0);

  Int ans = 0;
  TS.build(g[0]);
  for(auto e:E){
    Int a, b, c; tie(a,b,c) = e;
    Int k = min(TS.size(a), TS.size(b));
    ans += 2 * k * c;
  }

  if(g.size() == 1){
    Int mn = INF;
    for(auto e:E){
      Int a, b, c; tie(a,b,c) = e;
      if(a == g[0] || b == g[0]) Min(mn, c);
    }
    ans -= mn;
  }

  if(g.size() == 2){
    for(auto e:E){
      Int a, b, c; tie(a,b,c) = e;
      if((a == g[0] && b == g[1]) || (a == g[1] && b == g[0])) ans -= c;
    }
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 31512