// #includes {{{
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

//{{{ io
FILE *file_in=stdin,*file_out=stdout;
#define fin normal_in
#define fout normal_out
//const char fname[]="";
//FILE *fin=fopen(fname,"r"),*fout=fopen(fname,"w");
#ifdef __MINGW32__
#define LLD "%I64d"
#define LLU "%I64u"
#else
#define LLD "%lld"
#define LLU "%llu"
#endif
struct NORMAL_IN{
	bool cnt;
	NORMAL_IN():cnt(true){}
	operator int() const {return cnt;}
#define endl "\n"
	NORMAL_IN& operator>>(int &n){cnt=fscanf(file_in,"%d",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(unsigned int &n){cnt=fscanf(file_in,"%u",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(long long &n){cnt=fscanf(file_in,LLD,&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(unsigned long long &n){cnt=fscanf(file_in,LLU,&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(double &n){cnt=fscanf(file_in,"%lf",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(long double &n){cnt=fscanf(file_in,"%Lf",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(char *c){cnt=fscanf(file_in,"%s",c)!=EOF;return *this;}
	NORMAL_IN& operator>>(string &s){
		s.clear();
		for(bool r=false;;){
			const char c=getchar();
			if(c==EOF){ cnt=false; break;}
			const int t=isspace(c);
			if(!r and !t)r=true;
			if(r){
				if(!t)s.push_back(c);
				else break;
			}
		}
		return *this;
	}
	template<class T>
		NORMAL_IN& operator>>(vector<T> &v){
			int n;fscanf(file_in,"%d",&n);
			REP(i,n){
				T t;*this>>t;
				v.push_back(t);
			}
		}
} normal_in;

struct NORMAL_OUT{
	NORMAL_OUT& operator<<(const int &n){fprintf(file_out,"%d",n);return *this;}
	NORMAL_OUT& operator<<(const unsigned int &n){fprintf(file_out,"%u",n);return *this;}
	NORMAL_OUT& operator<<(const long long &n){fprintf(file_out,LLD,n);return *this;}
	NORMAL_OUT& operator<<(const unsigned long long &n){fprintf(file_out,LLU,n);return *this;}
	NORMAL_OUT& operator<<(const double &n){fprintf(file_out,"%lf",n);return *this;}
	NORMAL_OUT& operator<<(const long double &n){fprintf(file_out,"%Lf",n);return *this;}
	NORMAL_OUT& operator<<(const char c[]){fprintf(file_out,"%s",c);return *this;}
	NORMAL_OUT& operator<<(const string &s){fprintf(file_out,"%s",s.c_str());return *this;}
} normal_out;
//}}}

//{{{ Graph
typedef int Weight;
struct Edge {
	int src, dst, rev;
	Weight weight;
	Edge(int src, int dst, Weight weight=1,int rev=-1) :
		src(src), dst(dst), weight(weight), rev(rev) { }
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
		e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
//typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

struct Graph:vector<Edges>{
	Graph(){}
	Graph(const int &n){this->assign(n,Edges());}
	//add bi-directional edge
	void addBiEdge(int from ,int to, Weight w=1){
		while(this->size()<max(from,to)+1)this->push_back(Edges());
		this->at(from).push_back(Edge(from,to,w,this->at(to).size()));
		this->at(to).push_back(Edge(to,from,w,this->at(from).size()-1));
	}
	//add directional edge
	void addEdge(int from ,int to, Weight w=1){
		while(this->size()<from+1)this->push_back(Edges());
		this->at(from).push_back(Edge(from,to,w));
	}
};
#ifdef DEBUG
#include"graph/graphviz.h"
#endif
//}}}

//{{{ output graphviz
#include<fstream>

int ct=0;

//dot -Tpng graph.dot -o graph.png
void graphviz(const Graph &g,int base=0){
	bool weighed = false, directed = true;
	for(int u=0;u<g.size();u++)for(int i=0;i<g[u].size();i++){
		if(g[u][i].weight!=1)weighed=true;
		if(g[u][i].rev!=-1)directed = false;
	}
	FILE *fout=fopen("graph.dot","w");
	fprintf(fout,"digraph G{\n");
	fprintf(fout,"\tnode [style=rounded];\n");
	for(int u=0;u<g.size();u++){
		fprintf(fout,"\t%d[label=%d];\n",u,u+base);
	}
	for(int u=0;u<g.size();u++){
		for(int i=0;i<g[u].size();i++){
			if(g[u][i].rev!=-1 and u>g[u][i].dst)continue;
			fprintf(fout,"\t%d->%d",u,g[u][i].dst);
			fprintf(fout,"[");
			if(g[u][i].rev!=-1)fprintf(fout,"arrowhead=none,");
			else fprintf(fout,"arrowhead=normal,");
			if(weighed)fprintf(fout,"label=%d,",g[u][i].weight);
			fprintf(fout,"];\n");
		}
	}
	fprintf(fout,"}\n");
	fclose(fout);
	char command[100];
//	sprintf(command,"dot -Tpng graph.dot -o graph%d.png",ct);
	sprintf(command,"dot -Tpdf graph.dot -o graph%d.pdf",ct);
	system(command);
	ct++;
}
//}}}

Graph G;

vector<int> size, parent, pw;

int calc_size(int u,int w=-1,int p=-1){
	if(size[u]>=0)return size[u];
	parent[u] = p;
	pw[u] = w;
	int s = 1;
	for(auto &&e:G[u])if(e.dst!=p)s += calc_size(e.dst,e.weight,u);
	return size[u] = s;
}

void solve(int N, vector<int> A, vector<int> B, vector<int> C){
	G.assign(N,Edges());
	REP(i,A.size())G.addBiEdge(A[i],B[i],C[i]);
//	graphviz(G,1);
	size.assign(N,-1);
	parent.assign(N,-1);
	pw.assign(N,-1);
	calc_size(0);
	Graph H(N);
	Int ans = 0;
	Int mini = INF;
	for(int u=1;u<N;u++){
		//u -- parent[u]
		int v = parent[u];
		int su = size[u], sv = N - su;
		ans+=min(su,sv)*(Int)pw[u]*2ll;
		if(su!=sv){
			if(su<sv){
				H.addEdge(u,v,pw[u]);
			}else{
				H.addEdge(v,u,pw[u]);
			}
		}else{
			mini = pw[u];
		}
	}
	if(mini==INF){
		REP(u,H.size()){
			for(auto &&e:H[u]){
				if(H[e.dst].size()==0){
					mini = min(mini,(Int)e.weight);
				}
			}
		}
	}
	fout<<ans-mini<<endl;
}

int main(){	
	int N;
	fin >> N;
	vector<int> B((N-1)-1+1);
	vector<int> A((N-1)-1+1);
	vector<int> C((N-1)-1+1);
	for(int i = 0 ; i <= (N-1)-1 ; i++){
		fin >> A[i];
		fin >> B[i];
		fin >> C[i];
		A[i]--;B[i]--;
	}
	solve(N, A, B, C);
	return 0;
}



Measured memory_bytes: 21888