#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #define ll int using namespace std; const int maxn = 1000005; ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } int v[maxn],sum; int n,m,a,b,c; int main(){ freopen("debt.in","r",stdin); freopen("debt.out","w",stdout); n = read(); m = read(); for(int i = 1;i <= m;i++){ a = read(); b = read(); c = read(); v[a] -= c; v[b] += c; } for(int i = 1;i <= n;i++){ if(v[i] >= 0) sum += v[i]; else sum -= v[i]; } sum >>= 1; cout<<sum; return 0; }
时间: 2024-11-15 20:42:42