Skip to content

Instantly share code, notes, and snippets.

@fredbr
Created May 21, 2018 20:43
Show Gist options
  • Save fredbr/c2a1e7f99c2c1c0ce2fb8891ef58c61f to your computer and use it in GitHub Desktop.
Save fredbr/c2a1e7f99c2c1c0ce2fb8891ef58c61f to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int d[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int m, n;
cin >> m >> n;
int tot = 0;
for (int i = 0; i < m; i++) {
int a, b, v;
cin >> a >> v >> b;
tot += v;
d[a] -= v;
d[b] += v;
}
int ans = 0;
for (int i = 1; i <= n; i++) ans += abs(d[i]);
ans /= 2;
if (ans != tot) cout << "S" << "\n";
else cout << "N" << "\n";
cout << ans << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment