Submission #6823450


Source Code Expand

Copy
#include <iostream>
#include <vector>
#define REP(i, a, b) for (auto i = (a); i < (b); ++i)
using namespace std;

const long long inf = 1e18;

struct edge {
	int a, b;
	long long cost;
};

signed main() {
	long long n, m, p; cin >> n >> m >> p;

	vector<edge> e(m);
	REP(i, 0, m) {
		long long a, b, c; cin >> a >> b >> c;
		e[i].a = a - 1;
		e[i].b = b - 1;
		e[i].cost = - c + p;
	}

	vector<long long> d(n, inf);
	d[0] = 0;
	bool x = 0;
	for (int i = 0; i < 2 * n; ++i) {
		for (int j = 0; j < m; ++j)
			if (d[e[j].a] < inf)
				if (d[e[j].b] > d[e[j].a] + e[j].cost) {
					d[e[j].b] = max(-inf, d[e[j].a] + e[j].cost);
					if (i >= n && e[j].b == n - 1) x = 1;
				}
	}

	if (x || d[n - 1] == inf) cout <<  -1;
	else cout << max(0LL, -d[n - 1]);
}

Submission Info

Submission Time
Task E - Coins Respawn
User islingr
Language C++14 (GCC 5.4.1)
Score 500
Code Size 791 Byte
Status AC
Exec Time 134 ms
Memory 384 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 56
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49, b50, b51, b52, b53, b54, b55, b56
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 1 ms 256 KB
b06 AC 1 ms 256 KB
b07 AC 1 ms 256 KB
b08 AC 1 ms 256 KB
b09 AC 24 ms 256 KB
b10 AC 24 ms 256 KB
b11 AC 24 ms 256 KB
b12 AC 16 ms 256 KB
b13 AC 16 ms 256 KB
b14 AC 24 ms 256 KB
b15 AC 4 ms 384 KB
b16 AC 4 ms 384 KB
b17 AC 4 ms 384 KB
b18 AC 24 ms 256 KB
b19 AC 24 ms 256 KB
b20 AC 24 ms 256 KB
b21 AC 24 ms 384 KB
b22 AC 12 ms 256 KB
b23 AC 24 ms 256 KB
b24 AC 12 ms 256 KB
b25 AC 1 ms 256 KB
b26 AC 34 ms 384 KB
b27 AC 34 ms 384 KB
b28 AC 34 ms 384 KB
b29 AC 35 ms 384 KB
b30 AC 35 ms 384 KB
b31 AC 34 ms 384 KB
b32 AC 35 ms 384 KB
b33 AC 35 ms 384 KB
b34 AC 35 ms 384 KB
b35 AC 36 ms 384 KB
b36 AC 38 ms 384 KB
b37 AC 38 ms 384 KB
b38 AC 34 ms 384 KB
b39 AC 34 ms 384 KB
b40 AC 34 ms 384 KB
b41 AC 34 ms 384 KB
b42 AC 34 ms 384 KB
b43 AC 121 ms 384 KB
b44 AC 112 ms 384 KB
b45 AC 134 ms 384 KB
b46 AC 100 ms 384 KB
b47 AC 22 ms 384 KB
b48 AC 17 ms 256 KB
b49 AC 24 ms 256 KB
b50 AC 33 ms 256 KB
b51 AC 24 ms 256 KB
b52 AC 32 ms 256 KB
b53 AC 24 ms 256 KB
b54 AC 33 ms 384 KB
b55 AC 40 ms 384 KB
b56 AC 47 ms 384 KB