Buggy python submission (verdict: Runtime Error):
from scipy.sparse import*
m=csr_matrix
n,_,p,*t=map(int,open(0).read().split())
s=[n+1]*2
r,c,d=t[::3],t[1::3],[p-c for c in t[2::3]]
u=set(csgraph.depth_first_order(m((d,(r,c)),s),1,1,0))
v=set(csgraph.depth_first_order(m((d,(c,r)),s),n,1,0))
u&=v
E=[(r,c,d)for r,c,d in zip(r,c,d)if r in u and c in u]
D=[10**9]*(n+1)
D[1]=0
for _ in'_'*n:
	for a,b,c in E:D[b]=min(D[b],D[a]+c)
ans=D[n]
for a,b,c in E:
	if D[b]>D[a]+c:
		print(-1)
		exit()
print(max(-ans,0))

Fixed submission:
(N,M,P),*E=[list(map(int,s.split()))for s in open(0).readlines()]
D=[0]*2+[-9e9]*N
def f():
    for _ in D:
        for (a,b,c)in E:D[b]=max(D[b],D[a]+c-P)
    return D[N]
s=f()
print([max(s,0),-1][s<f()])

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse import*
m=csr_matrix
n,_,p,*t=map(int,open(0).read().split())
s=[n+1]*2
r,c,d=t[::3],t[1::3],[p-c for c in t[2::3]]
u=set(csgraph.depth_first_order(m((d,(r,c)),s),1,1,0))
v=set(csgraph.depth_first_order(m((d,(c,r)),s),n,1,0))
u&=v
E=[(r,c,d)for r,c,d in zip(r,c,d)if r in u and c in u]
D=[10**9]*(n+1)
D[1]=0
for _ in'_'*n:
	for a,b,c in E:D[b]=min(D[b],D[a]+c)
ans=D[n]
for a,b,c in E:
	if D[b]>D[a]+c:
		print(-1)
		exit()
print(max(-ans,0))

Fixed submission:
(N,M,P),*E=[list(map(int,s.split()))for s in open(0).readlines()]
D=[0]*2+[-9e9]*N
def f():
    for _ in D:
        for (a,b,c)in E:D[b]=max(D[b],D[a]+c-P)
    return D[N]
s=f()
print([max(s,0),-1][s<f()])

Buggy python submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse import csr_matrix, csgraph
dfs = csgraph.depth_first_order
n, m, p, *t = map(int, open(0).read().split())
row = np.int64([a-1 for a in t[::3]])
col = np.int64([b-1 for b in t[1::3]])
data = np.int64([p-c for c in t[2::3]])
graph = csr_matrix((data, (row, col)), (n, n))
rev = csr_matrix((data, (col, row)), (n, n))
use = set(dfs(graph, 0, True, False)) & set(dfs(rev, n-1, True, False))
flag = np.array([ r in use and c in use for r, c in zip(row, col)], '?')
g = csr_matrix((data[flag], (row[flag], col[flag])), (n, n))
try:
    print(max(0, int(-csgraph.bellman_ford(g, True, (0,))[n-1])))
except csgraph._shortest_path.NegativeCycleError:
    print(-1)

Fixed submission:
(N,M,P),*E=[list(map(int,s.split()))for s in open(0).readlines()]
D=[0]*2+[-9e9]*N
def f():
    for _ in D:
        for (a,b,c)in E:D[b]=max(D[b],D[a]+c-P)
    return D[N]
s=f()
print([max(s,0),-1][s<f()])

Buggy python submission (verdict: Time Limit Exceeded):
(N,M,P),*E=[list(map(int,s.split()))for s in open(0).readlines()]
D=[0]*2+[-9e9]*N
def f():
    for _ in D:
        for (a,b,c)in E:D[b]=max(D[b],D[a]+c-P)
    return D[N]
s=f()
print([max(s,0),-1][s<f()])

Fixed submission:
(N,M,P),*E=[list(map(int,s.split()))for s in open(0).readlines()]
D=[0]*2+[-9e9]*N
def f():
    for _ in D:
        for (a,b,c)in E:D[b]=max(D[b],D[a]+c-P)
    return D[N]
s=f()
print([max(s,0),-1][s<f()])

Buggy python submission (verdict: Runtime Error):
from scipy.sparse import*
N,M,P,*E=map(int,open(0).read().split())
D=csgraph.bellman_ford(csr_matrix(([P-c for c in E[5::3]],(E[3::3],E[4::3])),[N+1]*2),1,1)[N]
print(int([max(-D,0),-1][D>9e9]))

Fixed submission:
(N,M,P),*E=[list(map(int,s.split()))for s in open(0).readlines()]
D=[0]*2+[-9e9]*N
def f():
    for _ in D:
        for (a,b,c)in E:D[b]=max(D[b],D[a]+c-P)
    return D[N]
s=f()
print([max(s,0),-1][s<f()])