#include #include #include #include const int Max = 100 * 100 * 100 + 5; #define LL long long LL mod = 1e9+7; const LL INF = 1e9; //const int inx = INT_MAX; using namespace std; // srand(time(NULL)); // m = rand() % 1000 + 1; //定义i i(A) i+n i+n(B) i+n+n i+n+n(C) //bitsets,q; LL a[3005]; int main() { LL n,m,u,v,w; while(cin >> n >> m){ memset(a,0,sizeof(a)); int i,j; for(i = 1; i <= m; i++){ cin >> u >> v >> w; if(u == v) continue; a[u] += w; a[v] += w; } LL temp = INF; for(i = 1; i <= n; i++){ if(a[i] <= temp) temp = a[i]; } cout << temp << endl; } return 0; }