Problem Statement
High Score
Implementation
void solve() {
ll n, m;
cin >> n >> m;
vector<vpll> v(n);
rep(i, m) {
ll x, y, w;
cin >> x >> y >> w;
--x, --y;
v[x].pb({ y, -w });
}
vll d(n, inf);
d[0] = 0;
rep(i, n) {
rep(j, n) {
for (auto& child : v[j]) {
if (d[j] < inf && d[child.f] > d[j] + child.s) {
d[child.f] = max(-inf, d[j] + child.s);
}
}
}
}
rep(i, n) {
rep(j, n) {
for (auto& child : v[j]) {
if (d[j] < inf && d[child.f] > d[j] + child.s) {
d[child.f] = -inf;
}
}
}
}
if (d[n - 1] == -inf) cout << -1 << "\n";
else cout << -d[n - 1] << "\n";
}