#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class Egalitarianism3 { public:
	int maxCities(int n, vector <int> a, vector <int> b, vector <int> len)
	{
		if(n<=2)
			return n;

		const int INF = 0x3fffffff;
		vector<vector<int>> d(n, vector<int>(n, INF));
		for(int i=0; i<n; ++i)
			d[i][i] = 0;
		for(int i=0; i<a.size(); ++i) {
			d[a[i]-1][b[i]-1] = len[i];
			d[b[i]-1][a[i]-1] = len[i];
		}
		for(int k=0; k<n; ++k)
		for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j)
			d[i][j] = min(d[i][j], d[i][k]+d[k][j]);

		int best = 2;
		for(int c=0; c<n; ++c) {
			map<int, vector<int>> cand;
			for(int v=0; v<n; ++v) if(v!=c) {
				int rad = d[c][v];
				bool ok = true;
				for(int u: cand[rad])
					if(d[v][u] != 2*rad)
						ok = false;
				if(ok) {
					cand[rad].push_back(v);
					best = max<int>(best, cand[rad].size());
				}
			}
		}
		return best;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, Egalitarianism3().maxCities(n, a, b, len));}
int main(){

CASE(0)
	int n = 4; 
	int a_[] = {1,1,1};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int b_[] = {2,3,4};
	  vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_)); 
	int len_[] = {1,1,1};
	  vector <int> len(len_, len_+sizeof(len_)/sizeof(*len_)); 
	int _ = 3; 
END
CASE(1)
	int n = 6; 
	int a_[] = {1,2,3,2,3};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int b_[] = {2,3,4,5,6};
	  vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_)); 
	int len_[] = {2,1,3,2,3};
	  vector <int> len(len_, len_+sizeof(len_)/sizeof(*len_)); 
	int _ = 3; 
END
CASE(2)
	int n = 10; 
	int a_[] = {1,1,1,1,1,1,1,1,1};
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int b_[] = {2,3,4,5,6,7,8,9,10};
	  vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_)); 
	int len_[] = {1000,1000,1000,1000,1000,1000,1000,1000,1000};
	  vector <int> len(len_, len_+sizeof(len_)/sizeof(*len_)); 
	int _ = 9; 
END
CASE(3)
	int n = 1; 
	vector <int> a; 
	vector <int> b; 
	vector <int> len; 
	int _ = 1; 
END
/*
CASE(4)
	int n = ; 
	int a_[] = ;
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int b_[] = ;
	  vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_)); 
	int len_[] = ;
	  vector <int> len(len_, len_+sizeof(len_)/sizeof(*len_)); 
	int _ = ; 
END
CASE(5)
	int n = ; 
	int a_[] = ;
	  vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 
	int b_[] = ;
	  vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_)); 
	int len_[] = ;
	  vector <int> len(len_, len_+sizeof(len_)/sizeof(*len_)); 
	int _ = ; 
END
*/
}
// END CUT HERE
