Submission #6954405


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;
	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) {
                    if (i < n)
                        d[e[j].b] = max(-inf, min(inf, d[e[j].a] + e[j].cost));
                    else
                        d[e[j].b] = -inf;
                }
        }
	}

	if (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 907 Byte
Status AC
Exec Time 78 ms
Memory 764 KB

Judge Result

Set Name Sample All after_contest
Score / Max Score 0 / 0 500 / 500 0 / 0
Status
AC × 3
AC × 56
AC × 3
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
after_contest after_contest_57, after_contest_58, after_contest_59
Case Name Status Exec Time Memory
a01 AC 9 ms 764 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
after_contest_57 AC 18 ms 256 KB
after_contest_58 AC 18 ms 256 KB
after_contest_59 AC 18 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 18 ms 256 KB
b10 AC 18 ms 256 KB
b11 AC 18 ms 256 KB
b12 AC 16 ms 256 KB
b13 AC 16 ms 256 KB
b14 AC 18 ms 256 KB
b15 AC 4 ms 384 KB
b16 AC 4 ms 384 KB
b17 AC 4 ms 384 KB
b18 AC 18 ms 256 KB
b19 AC 18 ms 256 KB
b20 AC 18 ms 256 KB
b21 AC 18 ms 256 KB
b22 AC 12 ms 256 KB
b23 AC 22 ms 256 KB
b24 AC 12 ms 256 KB
b25 AC 1 ms 256 KB
b26 AC 33 ms 384 KB
b27 AC 33 ms 384 KB
b28 AC 33 ms 384 KB
b29 AC 53 ms 384 KB
b30 AC 53 ms 384 KB
b31 AC 53 ms 384 KB
b32 AC 34 ms 384 KB
b33 AC 34 ms 384 KB
b34 AC 35 ms 384 KB
b35 AC 35 ms 384 KB
b36 AC 37 ms 384 KB
b37 AC 37 ms 384 KB
b38 AC 33 ms 384 KB
b39 AC 33 ms 384 KB
b40 AC 33 ms 384 KB
b41 AC 33 ms 384 KB
b42 AC 33 ms 384 KB
b43 AC 68 ms 384 KB
b44 AC 57 ms 384 KB
b45 AC 78 ms 384 KB
b46 AC 53 ms 384 KB
b47 AC 22 ms 384 KB
b48 AC 17 ms 256 KB
b49 AC 18 ms 256 KB
b50 AC 22 ms 256 KB
b51 AC 18 ms 256 KB
b52 AC 22 ms 256 KB
b53 AC 18 ms 256 KB
b54 AC 32 ms 384 KB
b55 AC 37 ms 384 KB
b56 AC 43 ms 384 KB