#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair pll; typedef vector vll; typedef vector> vvll; #define for1(i,n) for (ll i=0;i<(n);i++) #define for2(i,m,n) for (ll i=(m);i<(n);i++) #define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d)) #define DEBUG 0 void solve() { ll N,M,i; cin >> N >> M; vector> to(N); for1(i,M) { ll a,b,c; cin >> a >> b >> c; --a; --b; to[a].push_back(make_pair(b,c)); to[b].push_back(make_pair(a,c)); } // ll ans = 0; // 駅iから出発する for1(i,N) { vector score(N,-1); priority_queue> q; q.push(make_tuple(0,i,0)); while (!q.empty()) { auto item = q.top(); q.pop(); ll sc = get<0>(item); ll loc = get<1>(item); ll arr = get<2>(item); if (score[loc] >= sc) { continue; } if ((arr & (1LL << loc)) != 0) { continue; } arr |= (1LL << loc); score[loc] = sc; for (auto t : to[loc]) { q.push(make_tuple(sc + t.second, t.first, arr)); } } for1(j,N) { ans = max(ans, score[j]); } } cout << ans << endl; } int main() { do { solve(); } while (DEBUG); }