#include #include #include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin>>N>>M; vector com(N+1, 0); for (int i=0;i>U>>V>>W; com[U]+=W; com[V]+=W; } sort(&com[1], &com[N+1], greater()); ll a=0, b=0; for (int i=1;i<=N;i++){ if (i%2==1) a+=com[i]; else b+=com[i]; } cout << (a-b)/2 << "\n"; return 0; }