#include #include #include #include #include using namespace std; #define mem(a,n) memset(a,n,sizeof(a)) typedef long long LL; const int N = 3e3 + 5; LL ans[N]; vectorvec; int main() { int n, m; while (~scanf("%d%d", &n, &m)) { LL u, v, w; mem(ans, 0); for (int i = 0; i < m; i++) { scanf("%lld%lld%lld", &u, &v, &w); if (u == v) continue;////相同时不进行累加 ans[u] += w; ans[v] += w; } sort(ans + 1, ans + n + 1); printf("%lld\n", ans[1]);///最少代价 } return 0; }