s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1
value | original_language stringclasses 11
values | filename_ext stringclasses 1
value | status stringclasses 1
value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s358201344 | p03722 | u745514010 | 1600278805 | Python | PyPy3 (7.3.0) | py | Runtime Error | 190 | 75700 | 978 | n, m = map(int, input().split())
g = []
for _ in range(m):
a, b, c = map(int, input().split())
g.append([a - 1, b - 1, -c])
def bellman_ford(s):
d = [float('inf')]*n # 各頂点への最小コスト
d[s] = 0 # 自身への距離は0
for i in range(n):
update = False # 更新が行われたか
for x, y, z in g:
if d[y] >... |
s572014863 | p03722 | u923662841 | 1599791144 | Python | Python (3.8.2) | py | Runtime Error | 466 | 10348 | 885 | #ABC061D
from collections import deque
N,M = map(int,input().split())
ABC = []
Adake = [[] for _ in range(M)]
Bdake = [[] for _ in range(M)]
for i in range(M):
a,b,c = map(int, input().split())
ABC.append((a-1,b-1,-c))
Adake[a-1].append(b-1)
Bdake[b-1].append(a-1)
def dfs(X,s):
used = {s}
sear... |
s388289233 | p03722 | u761320129 | 1599610794 | Python | Python (3.8.2) | py | Runtime Error | 1028 | 9444 | 379 | N,M = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]
INF = float('inf')
dist = [INF] * N
dist[0] = 0
for i in range(N):
for a,b,c in ABC:
a,b,c = a-1,b-1,-c
if dist[b] > dist[a] + c:
dist[b] = dist[a] + c
if i==N-1 and to == N-1:
... |
s521312443 | p03722 | u873059840 | 1599602073 | Python | Python (3.8.2) | py | Runtime Error | 130 | 18796 | 994 | N,M= map(int,input().split())
inf = 10**12 + 1
list=[[inf for i in range(N)] for j in range(N)]
for i in range (M):
a,b,c=map(int,input().split())
list[a-1][b-1]=c
flag = [inf for _ in range(N)]
value = -inf
def depth_search (now,tmp_flag,wage):
global value
tmp_flag[now] = wage
for i in range(0,... |
s781048436 | p03722 | u873059840 | 1599601995 | Python | Python (3.8.2) | py | Runtime Error | 195 | 18636 | 992 | N,M= map(int,input().split())
list=[[0 for i in range(N)] for j in range(N)]
for i in range (M):
a,b,c=map(int,input().split())
list[a-1][b-1]=c
inf = 10**12 + 1
flag = [inf for _ in range(N)]
value = -inf
def depth_search (now,tmp_flag,wage):
global value
tmp_flag[now] = wage
for i in range(0,N)... |
s124250469 | p03722 | u873059840 | 1599601435 | Python | Python (3.8.2) | py | Runtime Error | 120 | 18672 | 986 | N,M= map(int,input().split())
list=[[0 for i in range(N)] for j in range(N)]
for i in range (M):
a,b,c=map(int,input().split())
list[a-1][b-1]=c
inf = 10**12 + 1
flag = [0 for _ in range(N)]
value = -inf
def depth_search (now,tmp_flag,wage):
global value
tmp_flag[now] = wage
for i in range(0,N):
... |
s685643777 | p03722 | u437351386 | 1598718501 | Python | PyPy3 (7.3.0) | py | Runtime Error | 219 | 75884 | 725 | #ベルマンフォード法
#正の閉路がない時は普通のベルマンフォード法
n,m=list(map(int,input().split()))
es=[]
for i in range(m):
a,b,c=list(map(int,input().split()))
es.append((a-1,b-1,c))
import sys
def Bellmanford(n,m,s,es):
d=[-float("INF")]*n
d[s]=0
cnt=0
while(1):
update=False
for p,q,r in es:
if d[p]!=-float("INF") and d[... |
s830964762 | p03722 | u682672120 | 1598682669 | Python | PyPy3 (7.3.0) | py | Runtime Error | 178 | 79676 | 1271 | from collections import deque
def fast_bellman_ford(n, s, graph, edge_n, init_val): #どう?
d = [init_val] * n
d[s] = 0
q = deque([s])
checker = [-1] * n
for i in range(n):
m = len(q)
for _ in range(m):
vf = q.popleft()
for vt, w in graph[vf]:
if... |
s038748612 | p03722 | u682672120 | 1598681160 | Python | PyPy3 (7.3.0) | py | Runtime Error | 128 | 75496 | 2035 | class FixedSizeQueue:
def __init__(self, n, init_val):
self.queue = [init_val] * n #根にサイズを負の値で格納する。
self.l = 0
self.r = 0
self.n = n
self.size = 0
def append(self, val):
if self.size == self.n:
raise IndexError('fixed-size-queue is full')
self.... |
s205913130 | p03722 | u682672120 | 1598681102 | Python | PyPy3 (7.3.0) | py | Runtime Error | 128 | 75456 | 2031 | class FixedSizeQueue:
def __init__(self, n, init_val):
self.queue = [init_val] * n #根にサイズを負の値で格納する。
self.l = 0
self.r = 0
self.n = n
self.size = 0
def append(self, val):
if self.size == self.n:
raise IndexError('fixed-size-queue is full')
self.... |
s860121081 | p03722 | u682672120 | 1598669349 | Python | PyPy3 (7.3.0) | py | Runtime Error | 111 | 75892 | 999 | def moores_d(n, s, graph, init_val):
d = [init_val] * n
d[s] = 0
stack = [s]
for _ in range(n):
next_stack = []
for _ in range(m):
vf = stack.pop()
for vt, w in graph[vf]:
if d[vt] > d[vf] + w:
d[vt] = d[vf] + w
... |
s424300434 | p03722 | u923172145 | 1598549659 | Python | Python (3.8.2) | py | Runtime Error | 279 | 10192 | 1148 | INF = 10**30
def bellman_ford(s, g):
d = [INF for _ in range(n)] # 各頂点への最小コスト
d[s] = 0 # 自身への距離は0
for i in range(n):
update = False # 更新が行われたか
for x, y, z in g:
if d[y] > d[x] + z:
d[y] = d[x] + z
update = True
if not update:
br... |
s187058262 | p03722 | u819135704 | 1596043426 | Python | Python (3.8.2) | py | Runtime Error | 32 | 10124 | 583 | N, M = map(int, input().split())
R = [[] for _ in range(N)]
for _ in range(M):
a, b, c = map(int, input().split())
R[a - 1].append((b - 1, c))
INF = 10 ** 40
S = [-INF] * N
S[0] = 0
def score(fst, s, C):
for nx, p in R[fst]:
if S[nx] >= s + p or S[nx] >= INF:
continue
S[nx] = ... |
s083293753 | p03722 | u786020649 | 1595713984 | Python | Python (3.8.2) | py | Runtime Error | 37 | 9992 | 1463 | import sys
from collections import defaultdict
rl=sys.stdin.readline
def main():
n,m=map(int,rl().strip().split())
ewdata=[list(map(int,rl().strip().split())) for _ in range(m)]
ew=dict(((x[0],x[1]),x[2]) for x in ewdata)
ed=defaultdict(list)
deg=defaultdict(int)
memo=defaultdict(int)
for ... |
s192753119 | p03722 | u730769327 | 1594798788 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2211 | 224208 | 570 | import sys
sys.setrecursionlimit(2000)
n,m=map(int,input().split())
e=[[]for _ in range(n)]
for _ in range(m):
a,b,c=map(int,input().split())
e[a-1].append((b-1,c))
def dfs1(now,vis):
vis.append(now)
if now==n-1:
return 0
res=-10**18
for i,c in e[now]:
if i not in vis:
res=max(dfs1(i,vis[:])+c... |
s126009844 | p03722 | u730769327 | 1594798704 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2211 | 224228 | 531 | n,m=map(int,input().split())
e=[[]for _ in range(n)]
for _ in range(m):
a,b,c=map(int,input().split())
e[a-1].append((b-1,c))
def dfs1(now,vis):
vis.append(now)
if now==n-1:
return 0
res=-10**18
for i,c in e[now]:
if i not in vis:
res=max(dfs1(i,vis[:])+c,res)
return res
def dfs2(now,j,cnt)... |
s594768869 | p03722 | u860002137 | 1593380433 | Python | Python (3.8.2) | py | Runtime Error | 568 | 9512 | 467 | N, M = map(int, input().split())
edge = [list(map(int, input().split())) for _ in range(M)]
INF = 1 << 60
cost = [- INF] * (N + 1)
cost[1] = 0
for i in range(N):
for n, nn, c in edge:
if cost[nn] < cost[n] + c:
# ワーシャルフロイド法の性質より、N回目に更新があるならinf
if i == N - 1 and nn == N:
... |
s401444656 | p03722 | u860002137 | 1593377738 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 25356 | 792 | import sys
from collections import defaultdict
from collections import deque
n, m = map(int, input().split())
graph = defaultdict(list)
for _ in range(m):
a, b, c = map(int, input().split())
graph[a].append((b, c))
INF = 1 << 60
cost = [- INF] * (n + 1)
cost[1] = 0
for _ in range(n):
visited = [[False]... |
s381893888 | p03722 | u316464887 | 1591669753 | Python | Python (3.4.3) | py | Runtime Error | 402 | 25316 | 548 | #michatta ...
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import shortest_path
import scipy
def main():
N, M = map(int, input().split())
p = []
q = []
w = []
for _ in range(M):
a, b, c = map(int, input().split())
p.append(a-1)
q.append(b-1)
w.append(... |
s712627722 | p03722 | u316464887 | 1591669453 | Python | Python (3.4.3) | py | Runtime Error | 237 | 17152 | 556 | #michatta ...
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import shortest_path
import scipy
def main():
N, M = map(int, input().split())
p = []
q = []
w = []
for _ in range(M):
a, b, c = map(int, input().split())
p.append(a-1)
q.append(b-1)
w.append(... |
s814864877 | p03722 | u858742833 | 1591664383 | Python | Python (3.4.3) | py | Runtime Error | 80 | 4460 | 661 | def main():
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
a, b, c = map(int, input().split())
G[a - 1].append((b - 1, c))
INF = 10 ** 40
S = [-INF] * N
S[0] = 0
cur = set([0])
def helper(n, s, hist):
for g, gc in G[n]:
... |
s046595967 | p03722 | u034128150 | 1591109112 | Python | Python (3.4.3) | py | Runtime Error | 358 | 25288 | 650 | import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import bellman_ford
from scipy.sparse.csgraph._shortest_path import NegativeCycleError
input = sys.stdin.buffer.readline
N, M = map(int, input().split())
starts = []
ends = []
costs = []
for _ in range(M):
a, b, c = map(int, input().split()... |
s188678904 | p03722 | u034128150 | 1591107512 | Python | Python (3.4.3) | py | Runtime Error | 243 | 17264 | 674 | import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import bellman_ford
from scipy.sparse.csgraph._shortest_path import NegativeCycleError
input = sys.stdin.buffer.readline
N, M = map(int, input().split())
starts = []
ends = []
costs = []
for _ in range(M):
a, b, c = map(int, input().split()... |
s262743873 | p03722 | u446774692 | 1590624361 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 401 | N,M = map(int,input().split())
abc = []
for _ in range(M):
abc.append(list(map(int,input().split())))
cost = [-float('inf')]*N
cost[0] = 0
for i in range(2):
for a,b,c in abc:
a,b = a-1,b-1
cost[b] = max(cost[b], cost[a] + c)
if i == 0:
ans = cost[N-1]
else... |
s885329888 | p03722 | u679520304 | 1590072742 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 656 | import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
N,M = map(int,input().split())
start = []
goal = []
data1 = []
data2 = []
for _ in range(M):
a,b,c = map(int,input().split())
start.append(a)
goal.append(b)
... |
s450688534 | p03722 | u912862653 | 1590070626 | Python | PyPy3 (2.4.0) | py | Runtime Error | 318 | 65772 | 1004 | from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")
MOD = 1000000007
def bellman_ford(edges, num_v, sv):
#グラフの初期化
dist = [INF] * num_v
dist[sv]=0
#辺の緩和
for i in ... |
s770158211 | p03722 | u119148115 | 1589682845 | Python | PyPy3 (2.4.0) | py | Runtime Error | 259 | 42988 | 1887 | class BellmanFord():
def __init__(self, N):
self.N = N
self.edges = []
def add(self, u, v, d, directed=False):
"""
u = from, v = to, d = cost
directed = Trueのとき、有向グラフである。
"""
if directed is False:
self.edges.append([u, v, d])
self.... |
s175638265 | p03722 | u476604182 | 1589677306 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 562 | N,M,*L = map(int, open('0').read().split())
dic = [[] for i in range(N+1)]
for a,b,c in zip(*[iter(L)]*3):
dic[a].append(b)
ok = [False]*(N+1)
ok[1] = True
q = [1]
while q:
p = q.pop()
for v in dic[p]:
if not ok[v]:
ok[v] = True
q.append(v)
cnt = 0
dist = [-10**20]*(N+1)
dist[1] = 0
while True:
... |
s132056449 | p03722 | u496687522 | 1589604642 | Python | Python (3.4.3) | py | Runtime Error | 689 | 3376 | 827 | N, M = map(int, input().split())
edges = []
for i in range(M):
a, b, c = map(int, input().split())
edges.append([a, b, -c])
def bellman_ford(edges, N):
dist = [float('inf') for i in range(N)]
dist[0] = 0
for i in range(N-1):
for edge in edges:
if dist[edge[1] - 1] > dist[edge[0] ... |
s553261182 | p03722 | u497952650 | 1589455365 | Python | Python (3.8.2) | py | Runtime Error | 775 | 9324 | 609 | """
お借りしました.
https://tjkendev.github.io/procon-library/python/graph/bellman-ford.html
"""
N,M = map(int,input().split())
V = N
G = [[] for _ in range(M)]
for i in range(M):
a,b,c = map(int,input().split())
G[a-1].append((b-1,-c))
INF = 10**18
dist = [INF] * V
dist[0] = 0
update = 1
for _ in range(V):
upda... |
s496236202 | p03722 | u203843959 | 1588785501 | Python | Python (3.4.3) | py | Runtime Error | 25 | 3440 | 1670 | import sys
sys.setrecursionlimit(10**9)
N,M=map(int,input().split())
def find_negative_loop(n,w,es):
dist=[float("inf")]*n
#この始点はどこでもよい
dist[1]=0
for i in range(n):
for j in range(w):
e=es[j]
if dist[e[1]]>dist[e[0]]+e[2]:
dist[e[1]]=dist[e[0]]+e[2]
if i==n-1:
retur... |
s342996674 | p03722 | u203843959 | 1588782138 | Python | Python (3.4.3) | py | Runtime Error | 1882 | 709484 | 1564 | import sys
sys.setrecursionlimit(10**9)
N,M=map(int,input().split())
def find_negative_loop(n,w,es):
dist=[float("inf")]*n
#この始点はどこでもよい
dist[1]=0
for i in range(n):
for j in range(w):
e=es[j]
if dist[e[1]]>dist[e[0]]+e[2]:
dist[e[1]]=dist[e[0]]+e[2]
if i==n-1:
retur... |
s004664259 | p03722 | u203843959 | 1588781945 | Python | Python (3.4.3) | py | Runtime Error | 1767 | 709484 | 1542 | import sys
sys.setrecursionlimit(10**9)
N,M=map(int,input().split())
def find_negative_loop(n,w,es):
dist=[float("inf")]*n
#この始点はどこでもよい
dist[1]=0
for i in range(n):
for j in range(w):
e=es[j]
if dist[e[1]]>dist[e[0]]+e[2]:
dist[e[1]]=dist[e[0]]+e[2]
if i==n-1:
retur... |
s564176523 | p03722 | u203843959 | 1588781899 | Python | Python (3.4.3) | py | Runtime Error | 335 | 4376 | 1502 | N,M=map(int,input().split())
def find_negative_loop(n,w,es):
dist=[float("inf")]*n
#この始点はどこでもよい
dist[1]=0
for i in range(n):
for j in range(w):
e=es[j]
if dist[e[1]]>dist[e[0]]+e[2]:
dist[e[1]]=dist[e[0]]+e[2]
if i==n-1:
return True
return False
def shortest_path... |
s202075017 | p03722 | u952467214 | 1588642973 | Python | Python (3.4.3) | py | Runtime Error | 392 | 3444 | 849 | import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
n, m = map(int, input().split())
abc = [tuple(map(int,input().split())) for i in range(m)]
es = [[] for i in range(n)]
for i,(a,b,c) in enumerate(abc):
a,b = a-1,b-1
es[i]=[a,b,c]
INF = float('inf')
#True : 負の経路が存在する
def find_negative_loop... |
s315333478 | p03722 | u349091349 | 1588571298 | Python | PyPy3 (2.4.0) | py | Runtime Error | 182 | 38384 | 659 | import sys
def BellmanFord(edges,num_v,source):
#グラフの初期化
inf=float("inf")
dist=[inf for i in range(num_v)]
dist[source-1]=0
#辺の緩和
for i in range(num_v):
for edge in edges:
#print(dist)
if edge[0] != inf and dist[edge[1]-1] > dist[edge[0]-1] + edge[2]:
... |
s482421325 | p03722 | u042113240 | 1588342102 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 652 | N, M = map(int, input().split())
adjacent = []
score = ['None' for i in range(N)]
score[0] = 0
for i in range(M):
a, b, c = map(int, input().split())
adjacent.append([a-1, b-1, c])
for i in range(2N):
for j in adjacent:
if score[j[1]] == 'None' and score[j[0]] != 'None':
score[j[1]] = score[j[... |
s568515682 | p03722 | u042113240 | 1588339740 | Python | Python (3.4.3) | py | Runtime Error | 1149 | 3424 | 632 | N, M = map(int, input().split())
adjacent = []
score = ['None' for i in range(N)]
score[0] = 0
for i in range(M):
a, b, c = map(int, input().split())
adjacent.append([a-1, b-1, c])
for i in range(N-1):
for j in adjacent:
if score[j[1]] == 'None' and score[j[0]] != 'None':
score[j[1]] = score[j... |
s480083396 | p03722 | u843135954 | 1587685457 | Python | Python (3.4.3) | py | Runtime Error | 118 | 36476 | 843 | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
import copy
n,m = na()
g = [[] for i in range(n)]
for i in range(m):
a,b,c = na()
a,b = a-1... |
s289974811 | p03722 | u145600939 | 1587676525 | Python | PyPy3 (2.4.0) | py | Runtime Error | 269 | 45680 | 928 | class BellmanFord:
def __init__(self,v,start):
self.inf = float('inf')
self.dist = [self.inf]*v
self.dist[start] = 0
self.edge = []
self.v = v
def add(self,f,t,cost):
self.edge.append((f,t,cost))
def build(self,gorl):
for _ in range(self.v - ... |
s138759516 | p03722 | u189479417 | 1587589015 | Python | Python (3.4.3) | py | Runtime Error | 993 | 3572 | 651 | import sys
N, M = map(int,input().split())
es = []
for _ in range(M):
e = list(map(int,input().split()))
e[2] *= -1
es.append(e)
INF = float('inf')
d = [INF for _ in range(N+1)]
d[1] = 0
negative = [0 for _ in range(N+1)]
for i in range(N):
for j in range(M):
e = es[j]
if d[e[1]] > d[e... |
s654387941 | p03722 | u931173291 | 1587141003 | Python | Python (3.4.3) | py | Runtime Error | 162 | 3444 | 485 | n,m=map(int,input().split())
x=[list(map(int,input().split())) for i in range(m)]
dp=[0 for i in range(n+1)]
import sys
# for i in range(m):
# if x[i][0]:
# print('inf')
# sys.exit()
for i in range(2,n+1):
ans=[]
for k in range(m):
if x[k][1]==i:
if x[k][1]<=x[k][0]:
... |
s941952145 | p03722 | u931173291 | 1587140685 | Python | Python (3.4.3) | py | Runtime Error | 156 | 3480 | 369 | n,m=map(int,input().split())
x=[list(map(int,input().split())) for i in range(m)]
dp=[0 for i in range(n+1)]
import sys
for i in range(m):
if x[i][0]==n:
print('inf')
sys.exit()
for i in range(2,n+1):
ans=[]
for k in range(m):
if x[k][1]==i:
ans.append(dp[x[k][0]]+x[k][2]... |
s774960132 | p03722 | u931173291 | 1587139269 | Python | Python (3.4.3) | py | Runtime Error | 166 | 3444 | 371 | n,m=map(int,input().split())
x=[list(map(int,input().split())) for i in range(m)]
dp=[0 for i in range(n+1)]
import sys
for i in range(m):
if x[i][0]==n:
print('inf')
sys.exit()
for i in range(2,n+1):
ans=[]
for k in range(m):
if x[k][1]==i:
ans.append(dp[x[k][0]]+x[k][2]... |
s260970279 | p03722 | u181801282 | 1587086701 | Python | Python (3.4.3) | py | Runtime Error | 2112 | 21776 | 534 | N,M=map(int,input().split())
V=[False]*N
G=[[False for _ in range(N)] for _ in range(N)]
W=[[0 for _ in range(N)] for _ in range(N)]
for i in range(M):
a,b,c=map(int,input().split())
G[a-1][b-1]=True
G[b-1][a-1]=True
W[a-1][b-1]=c
W[b-1][a-1]=c
flg=False
ans=0
def dfs(v,w):
global ans, flg
if v==N-1:
... |
s490123616 | p03722 | u790710233 | 1586560578 | Python | Python (3.4.3) | py | Runtime Error | 308 | 37484 | 444 | from scipy.sparse.csgraph import csgraph_from_dense, bellman_ford
from scipy.sparse.csgraph._shortest_path import NegativeCycleError
n, m = map(int, input().split())
GRAPH = [[0]*n for _ in range(n)]
for _ in range(m):
a, b, c = map(int, input().split())
a -= 1
b -= 1
GRAPH[a][b] = -c
try:
sp = b... |
s548675619 | p03722 | u654470292 | 1586497531 | Python | PyPy3 (2.4.0) | py | Runtime Error | 164 | 38384 | 2292 | import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in... |
s178443695 | p03722 | u479638406 | 1585880932 | Python | Python (3.4.3) | py | Runtime Error | 944 | 3700 | 514 | n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
a = [[a[i][0], a[i][1], a[i][2]*(-1)] for i in range(m)]
point = [0] + ['inf']*(n-1)
for j in range(n):
for i in range(m):
if point[a[i][1]-1] == 'inf' or point[a[i][1]-1] > point[a[i][0]-1] + a[i][2]:
point[a[i]... |
s718038094 | p03722 | u479638406 | 1585880530 | Python | Python (3.4.3) | py | Runtime Error | 914 | 3700 | 491 | n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
a = [[a[i][0], a[i][1], a[i][2]*(-1)] for i in range(m)]
point = [0] + ['inf']*(n-1)
for j in range(n):
for i in range(m):
if point[a[i][1]-1] == 'inf' or point[a[i][1]-1] > point[a[i][0]-1] + a[i][2]:
point[a[i]... |
s974442074 | p03722 | u479638406 | 1585879637 | Python | Python (3.4.3) | py | Runtime Error | 919 | 3700 | 494 | n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
a = [[a[i][0], a[i][1], a[i][2]*(-1)] for i in range(m)]
point = [0] + ['inf']*(n-1)
for j in range(n):
for i in range(m):
if point[a[i][1]-1] == 'inf' or point[a[i][1]-1] > point[a[i][0]-1] + a[i][2]:
point[a[i]... |
s726033626 | p03722 | u704284486 | 1585423778 | Python | Python (3.4.3) | py | Runtime Error | 966 | 3308 | 1322 | INF = float('inf')
class BellmanFord:
def bellmanford(self,s,V,E):
dist = [INF for _ in range(V)]
dist[s] = 0
while (True):
update = False
for e in E:
u,v,cost = e
if dist[u] != INF and dist[v] > dist[u] + cost:
... |
s306548834 | p03722 | u704284486 | 1585423735 | Python | Python (3.4.3) | py | Runtime Error | 25 | 3308 | 1322 | INF = float('inf')
class BellmanFord:
def bellmanford(self,s,V,E):
dist = [INF for _ in range(V)]
dist[s] = 0
while (True):
update = False
for e in E:
u,v,cost = e
if dist[u] != INF and dist[v] > dist[u] + cost:
... |
s023572224 | p03722 | u955251526 | 1584875342 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 430 | n, m = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(m)]
inf = 10 ** 18
dis = [inf] * n
dis[0] = 0
for z in range(n+1)
update = False
for a, b, c in edge:
a -= 1
b -= 1
if dis[a] != inf and dis[b] > dis[a] - c:
dis[b] = dis[a] - c
... |
s653421533 | p03722 | u955251526 | 1584874414 | Python | Python (3.4.3) | py | Runtime Error | 611 | 3316 | 428 | n, m = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(m)]
inf = 10 ** 18
dis = [inf] * n
dis[0] = 0
for z in range(n+1):
update = False
for a, b, c in edge:
a -= 1
a -= 1
if dis[a] != inf and dis[b] > dis[a] - c:
dis[b] = dis[a] - c
... |
s974064959 | p03722 | u358254559 | 1584808951 | Python | PyPy3 (2.4.0) | py | Runtime Error | 577 | 46808 | 908 | n,m = map(int, input().split())
link = []
for i in range(m):
tmp = list(map(int,input().split()))
link.append([tmp[0]-1,tmp[1]-1,-tmp[2]])
def bell(edges, start,num_v):
cost = [float('inf')] * num_v
cost[start] = 0
for _ in range(num_v):
updated = False
for a, b, c in edges:
... |
s359330013 | p03722 | u358254559 | 1584808864 | Python | PyPy3 (2.4.0) | py | Runtime Error | 323 | 45032 | 899 | n,m = map(int, input().split())
link = []
for i in range(m):
tmp = list(map(int,input().split()))
link.append([tmp[0]-1,tmp[1]-1,-tmp[2]])
def bell(edges, start,num_v):
cost = [float('inf')] * num_v
cost[start] = 0
for _ in range(num_v):
updated = False
for a, b, c in edges:
... |
s679758807 | p03722 | u170324846 | 1584044655 | Python | PyPy3 (2.4.0) | py | Runtime Error | 367 | 48232 | 585 | V, E = map(int, input().split())
G = [[] for i in range(V+1)]
for i in range(E):
a, b, c = map(int, input().split())
G[a-1].append((b-1, 0-c))
G[V-1].append((V, 0))
INF = float('inf')
dist = [INF] * (V + 1)
dist[0] = 0
Flag = False
for i in range(V+1):
UnUpdate = True
for v, e in enumerate(G):
... |
s866061834 | p03722 | u893063840 | 1583800040 | Python | Python (3.4.3) | py | Runtime Error | 2108 | 43808 | 1043 | from scipy.sparse.csgraph import bellman_ford, csgraph_from_dense, NegativeCycleError
import numpy as np
n, m = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]
adj = [[] for _ in range(n)]
for a, b, c in abc:
a -= 1
b -= 1
adj[a].append([b, -c])
g = [[np.inf] * n for _ in range... |
s682252858 | p03722 | u893063840 | 1583798787 | Python | Python (3.4.3) | py | Runtime Error | 567 | 43860 | 988 | from scipy.sparse.csgraph import bellman_ford, csgraph_from_dense
import numpy as np
n, m = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]
adj = [[] for _ in range(n)]
for a, b, c in abc:
a -= 1
b -= 1
adj[a].append([b, -c])
g = [[np.inf] * n for _ in range(n)]
def dfs(s):
... |
s900667512 | p03722 | u893063840 | 1583798729 | Python | Python (3.4.3) | py | Runtime Error | 594 | 69168 | 977 | from scipy.sparse.csgraph import bellman_ford
from scipy.sparse import csr_matrix
import numpy as np
n, m = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]
adj = [[] for _ in range(n)]
for a, b, c in abc:
a -= 1
b -= 1
adj[a].append([b, -c])
g = [[np.inf] * n for _ in range(n)]... |
s466938566 | p03722 | u498487134 | 1583698630 | Python | PyPy3 (2.4.0) | py | Runtime Error | 195 | 39920 | 2439 | import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
class BellmanFord():
class Edge():
""" 重み付き有向辺 """
def __init__(self, _from, _to, _cost):
self.from_ = _from
self.t... |
s286384348 | p03722 | u237362582 | 1582758011 | Python | PyPy3 (2.4.0) | py | Runtime Error | 543 | 47192 | 916 | N, M = map(int, input().split())
paths = [list(map(int, input().split())) for _ in range(M)]
minimumScore = [-float('inf') for _ in range(N)]
minimumScore[0] = 0
count = 0
while count < N:
flag = False
for a, b, c in paths:
if minimumScore[a-1] == -float('inf'):
continue
if minimumS... |
s480856560 | p03722 | u665873062 | 1582646937 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 1296 | #Nは頂点数, Mは辺数(2 <= N <= 1000, 1 <= M <= min(N(N-1, 2000)))
#頂点1から頂点Nに移動して、移動スコアを最大にする
#->移動スコアを正負反転させれば最短経路問題
#->負閉路を考慮してベルマンフォード法を利用
INF = 1 << 50
N,M = map(int,input().split())
#辺を登録
Sides = []
for i in range (M):
Sides.append(map(int,input().split()))
#コストを反転
Sides[i][2] = Sides[i][2] * (-1)
#各頂点の最短距離を初期化
... |
s403620751 | p03722 | u476604182 | 1582412262 | Python | PyPy3 (2.4.0) | py | Runtime Error | 189 | 39152 | 946 | N, M, *L = map(int, open(0).read().split())
dic = defaultdict(list)
rdic = defaultdict(list)
nin = [0]*N
Els = []
for a,b,c in zip(*[iter(L)]*3):
dic[a-1] += [b-1]
rdic[b-1] += [a-1]
nin[b-1] += 1
Els += [(a-1,b-1,-c)]
To = [False]*N
From = [False]*N
q = [0]
To[0] = True
while q:
p = q.pop()
for e in dic[p... |
s164915524 | p03722 | u779455925 | 1582070965 | Python | PyPy3 (2.4.0) | py | Runtime Error | 354 | 68712 | 1094 | from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *
from heapq import *
import copy
#input()
N,M=map(int,input().split())
ABC=[list(map(int,input().split())) for i in range(M)]
data=[[] for i in range(N+1)]
for a,b,c in ABC:
data[a].append([b,c... |
s811338782 | p03722 | u311379832 | 1581880800 | Python | PyPy3 (2.4.0) | py | Runtime Error | 371 | 47576 | 691 | INF = 10 ** 18
N, M = map(int, input().split())
abc = []
d = [INF] * N
d[0] = 0
loop = [False] * N
for i in range(M):
a, b, c = map(int, input().split())
abc.append([a - 1, b - 1, -c])
for j in range(N):
for i in range(M):
if d[abc[i][1]] > d[abc[i][0]] + abc[i][2]:
d[abc[i][1]] = d[a... |
s591279906 | p03722 | u311379832 | 1581880704 | Python | PyPy3 (2.4.0) | py | Runtime Error | 384 | 48088 | 713 | INF = 10 ** 18
N, M = map(int, input().split())
abc = []
d = [INF] * N
d[0] = 0
loop = [False] * N
for i in range(M):
a, b, c = map(int, input().split())
abc.append([a - 1, b - 1, -c])
for j in range(N):
for i in range(M):
if d[abc[i][0]] != INF and d[abc[i][1]] > d[abc[i][0]] + abc[i][2]:
... |
s989485961 | p03722 | u905582793 | 1581229385 | Python | Python (3.4.3) | py | Runtime Error | 274 | 14340 | 465 | import scipy
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import bellman_ford
n,m = map(int,input().split())
evv = [list(map(int,input().split())) for i in range(m)]
for i in range(m):
evv[i][2] = -evv[i][2]
evv[i][0] -= 1
evv[i][1] -= 1
v1,v2,edge = zip(*evv)
csr = csr_matrix((edge,(v1,v2)),sha... |
s819965030 | p03722 | u702786238 | 1581108612 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3188 | 588 | def BellmanFord(sv, ev, cv, num_v, source):
#グラフの初期化
inf=float("inf")
dist=[inf for i in range(num_v)]
dist[source-1]=0
#辺の緩和
for i in range(num_v):
for s,e,c in zip(sv, ev, cv):
if dist[0] != inf and dist[e-1] > dist[s-1] + c:
dist[e-1] = dist[s-1] + c
if i == n-1 and e == n-1:... |
s438550403 | p03722 | u702786238 | 1581107484 | Python | Python (3.4.3) | py | Runtime Error | 842 | 3316 | 579 | def BellmanFord(sv, ev, cv, num_v, source):
#グラフの初期化
inf=float("inf")
dist=[inf for i in range(num_v)]
dist[source-1]=0
#辺の緩和
for i in range(num_v):
for s,e,c in zip(sv, ev, cv):
if dist[0] != inf and dist[e-1] > dist[s-1] + c:
dist[e-1] = dist[s-1] + c
if i==num_v-1: return "in... |
s707834282 | p03722 | u702786238 | 1581107423 | Python | Python (3.4.3) | py | Runtime Error | 835 | 3188 | 564 | def BellmanFord(sv, ev, cv, num_v, source):
#グラフの初期化
inf=float("inf")
dist=[inf for i in range(num_v)]
dist[source-1]=0
#辺の緩和
for i in range(num_v):
for s,e,c in zip(sv, ev, cv):
if dist[0] != inf and dist[e-1] > dist[s-1] + c:
dist[e-1] = dist[s-1] + c
if i==num_v-1: return 1
... |
s738109043 | p03722 | u702786238 | 1581107272 | Python | Python (3.4.3) | py | Runtime Error | 842 | 3316 | 564 | def BellmanFord(sv, ev, cv, num_v, source):
#グラフの初期化
inf=float("inf")
dist=[inf for i in range(num_v)]
dist[source-1]=0
#辺の緩和
for i in range(num_v):
for s,e,c in zip(sv, ev, cv):
if dist[0] != inf and dist[e-1] > dist[s-1] + c:
dist[e-1] = dist[s-1] + c
if i==num_v-1: return -1
... |
s254089009 | p03722 | u170183831 | 1580952761 | Python | Python (3.4.3) | py | Runtime Error | 370 | 3444 | 533 | def solve(n, m, ABC):
distance = [None] * n
distance[0] = 0
for _ in range(n):
for a, b, c in ABC:
if distance[b - 1] is None or distance[b - 1] < distance[a - 1] + c:
distance[b - 1] = distance[a - 1] + c
for a, b, c in ABC:
if distance[b - 1] is None or di... |
s322372860 | p03722 | u170183831 | 1580951472 | Python | Python (3.4.3) | py | Runtime Error | 827 | 3572 | 558 | def solve(n, m, ABC):
distance = [None] * n
distance[0] = 0
for _ in range(n):
for a, b, c in ABC:
if distance[a - 1] is not None and \
(distance[b - 1] is None or distance[b - 1] < distance[a - 1] + c):
distance[b - 1] = distance[a - 1] + c
for a, b... |
s941898061 | p03722 | u170183831 | 1580951397 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 556 | def solve(n, m, ABC):
distance = [None] * n
distance[0] = 0
for _ in range(n):
for a, b, c in ABC:
if distance[a - 1] is not None and
(distance[b - 1] is None or distance[b - 1] < distance[a - 1] + c):
distance[b - 1] = distance[a - 1] + c
for a, b, ... |
s233550509 | p03722 | u170183831 | 1580951288 | Python | Python (3.4.3) | py | Runtime Error | 463 | 3568 | 556 | def solve(n, m, ABC):
distance = [None] * n
distance[0] = 0
for _ in range(n):
for a, b, c in ABC:
if distance[a - 1] is not None and \
distance[b - 1] is None or distance[b - 1] < distance[a - 1] + c:
distance[b - 1] = distance[a - 1] + c
for a, b, ... |
s943161936 | p03722 | u170183831 | 1580951179 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3444 | 511 | def solve(n, m, ABC):
distance = [None] * n
distance[0] = 0
for _ in range(n):
for a, b, c in ABC:
if distance[a - 1] is not None and distance[b - 1] < distance[a - 1] + c:
distance[b - 1] = distance[a - 1] + c
for a, b, c in ABC:
if distance[b - 1] < distan... |
s231838620 | p03722 | u170183831 | 1580950219 | Python | Python (3.4.3) | py | Runtime Error | 84 | 4920 | 764 | def solve(n, m, ABC):
g = [[] for _ in range(n)]
for a, b, c in ABC:
g[a - 1].append((b - 1, c))
distance = [-10 ** 10] * n
distance[0] = 0
parents = [-1] * n
ng = [False]
def search(node):
if ng[0]:
return
for to, d in g[node]:
if node == pa... |
s558364116 | p03722 | u594244257 | 1580944824 | Python | Python (3.4.3) | py | Runtime Error | 88 | 4480 | 1205 | def solve():
N,M = map(int, input().split())
graph_cod = [[] for _ in range(N+1)]
min_val = -1*(10**18)
INF = 10**18
for _ in range(M):
a,b,c = map(int, input().split())
graph_cod[b].append((a,c))
ret = 0
stack = [N]
searched = [False]*(N+1)
searched_nodes = ... |
s033418157 | p03722 | u280978334 | 1580679593 | Python | PyPy3 (2.4.0) | py | Runtime Error | 193 | 38512 | 1000 | from math import ceil,log2
def Bellman_Ford(node_num:int,start:int,VWC:list)->list:
Ans = [float("inf")]*(node_num + 1)
node = start
Ans[start] = 0
changeable = {}
for v,w,c in VWC:
if v not in changeable:
changeable[v] = True
if w not in changeable:
changeab... |
s088961529 | p03722 | u386170566 | 1580263346 | Python | Python (3.4.3) | py | Runtime Error | 960 | 3360 | 634 | #ABC061D - Score Attack
#https://atcoder.jp/contests/abc061/tasks/abc061_d
#自己考察
import sys
n, m = list(map(int,input().split()))
lst = [[] for _ in range(n+1)]#*(n+1)の挙動がよくわからない
for i in range(n):
a, b, c = list(map(int,input().split()))
lst[a].append((b,-c))
dp = [float("Inf")]*(n+1)
dp[1] = 0
for _ in rang... |
s107298034 | p03722 | u576917603 | 1579754119 | Python | Python (3.4.3) | py | Runtime Error | 26 | 3424 | 1120 | def shortest_path(s,n,w,es):
#s→iの最短距離
# s:始点, n:頂点数, w:辺の数, es[i]: [辺の始点,辺の終点,辺のコスト]
d = [float('inf')] * n
#d[i] : s→iの最短距離
d[s] = 0
while True:
update = False
for p,q,r in es:
# e: 辺iについて [from,to,cost]
#print(d,p,q,r)
if d[p] != float('inf') and d[q] >... |
s710443837 | p03722 | u353797797 | 1578354457 | Python | Python (3.4.3) | py | Runtime Error | 21 | 3316 | 985 | import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_num... |
s748642913 | p03722 | u572193732 | 1578172766 | Python | Python (3.4.3) | py | Runtime Error | 577 | 3388 | 506 | INF = float('inf')
def bellmanford(n, edges, r): # r : start
d = [INF] * n
d[r] = 0
for i in range(n):
for (u, v, c) in edges:
if d[u] != INF and d[u] + c < d[v]:
d[v] = d[u] + c
if i == n-1 and v == n-1:
return 'inf'
return d[n-1]... |
s791089717 | p03722 | u588341295 | 1578028924 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 1819 | # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a... |
s307345337 | p03722 | u581187895 | 1577835650 | Python | Python (3.4.3) | py | Runtime Error | 178 | 15988 | 893 | import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import bellman_ford
from scipy.sparse.csgraph import connected_components
N,M = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in range(N)]
row, col, val = zip(*ABC)
# -1倍しておいて最短路問題にする
val = [-(x) for x in val]
grap... |
s535479605 | p03722 | u231122239 | 1577656373 | Python | Python (3.4.3) | py | Runtime Error | 837 | 3444 | 1292 | def bellman_ford(edges, n, src):
# n:ノード数, src:スタートノード
# edges:edge(src, tgt, cost)のリスト
inf = float('inf')
dist = [inf for _ in range(n)]
dist[src] = 0
# 移動経路
pre = {}
# 最短経路算出
for i in range(n-1):
for edge in edges:
# srcにコストがあり、tgtのコストよりも低いコストで更新できそうなら
... |
s948512744 | p03722 | u944460773 | 1576714576 | Python | Python (3.4.3) | py | Runtime Error | 711 | 4072 | 2304 | # coding:utf-8
from pprint import pprint
def bellman_ford(V, E, s):
""" 始点sから残りのノードへの最短経路を求めるベルマンフォード法
:param V: 頂点数
:param E: (ノード1, ノード2, コスト)のタプルのリスト
:param s: 始点とするノード
:return : (距離リスト, 最短経路, 負の辺によるループが存在するか)a
"""
##### 前処理 #####
from collections import defaultdict
# INFの定義
... |
s026629911 | p03722 | u825769322 | 1576714201 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3064 | 2455 | from pprint import pprint
def bellman_ford(V, E, s):
""" 始点sから残りのノードへの最短経路を求めるベルマンフォード法
:param V: 頂点数
:param E: (ノード1, ノード2, コスト)のタプルのリスト
:param s: 始点とするノード
:return : (距離リスト, 最短経路, 負の辺によるループが存在するか)a
"""
##### 前処理 #####
from collections import defaultdict
# INFの定義
INF = -10 ** 10... |
s344694261 | p03722 | u190406011 | 1575659460 | Python | PyPy3 (2.4.0) | py | Runtime Error | 264 | 42732 | 981 | import sys
n, m = [int(i) for i in sys.stdin.readline().split()]
graph = {i : [] for i in range(n)}
edge_ls = []
for i in range(m):
a, b, c = [int(i) for i in sys.stdin.readline().split()]
a -= 1
b -= 1
graph[a].append((b, c))
edge_ls.append((a, b, c))
INF = float("inf")
d = [-INF for i in range(n)... |
s990366409 | p03722 | u470542271 | 1575523291 | Python | Python (3.4.3) | py | Runtime Error | 784 | 45652 | 304 | n, m = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]
cost = [[float('inf')] * n for _ in range(n)]
for a, b, c in abc:
cost[a-1][b-1] = -c
from scipy.sparse.csgraph import floyd_warshall
dist = floyd_warshall(cost)
# print(int(-1 * dist[0][n-1]))
print('inf')
|
s817946566 | p03722 | u470542271 | 1575522923 | Python | Python (3.4.3) | py | Runtime Error | 783 | 45660 | 296 | n, m = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]
cost = [[float('inf')] * n for _ in range(n)]
for a, b, c in abc:
cost[a-1][b-1] = -c
from scipy.sparse.csgraph import floyd_warshall
dist = floyd_warshall(cost)
print(int(round(-1 * dist[0][n-1])))
|
s344317304 | p03722 | u682985065 | 1574568462 | Python | PyPy3 (2.4.0) | py | Runtime Error | 466 | 45400 | 784 | def bellman_ford(n, edges, s, distance=None):
if distance != None:
d = distance.copy()
else :
d = [float('inf')] * n
d[s] = 0
loop_cnt = 0
while True:
loop_cnt += 1
update = False
for i in range(len(edges)):
e = edges[i]
if d[e... |
s447153782 | p03722 | u682985065 | 1574565829 | Python | Python (3.4.3) | py | Runtime Error | 1191 | 3388 | 670 | def bellman_ford(n, edges, s):
d = [float('inf')] * n
d[s] = 0
loop_cnt = 0
while True:
loop_cnt += 1
update = False
for i in range(len(edges)):
e = edges[i]
if d[e[0]] != float('inf') and d[e[1]] > d[e[0]] + e[2]:
d[e[1]] = d[e[0]] + ... |
s402400211 | p03722 | u504836877 | 1574555393 | Python | Python (3.4.3) | py | Runtime Error | 458 | 3316 | 1029 | N,M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
a, b, c = map(int, input().split())
E[a-1].append((b-1, -c))
#ベルマンフォード法:負閉路の検出とある一点から他のすべての点への最短距離の算出
def BellmanFord(E, N, M, source):
#E:E[a]は頂点aを始点とする辺のリストであり、辺の終点bと辺の重みwが(b, w)の形で格納されている
#N:頂点の数
#M:辺の数
#... |
s658528606 | p03722 | u073852194 | 1574207755 | Python | PyPy3 (2.4.0) | py | Runtime Error | 426 | 47576 | 947 | INF = 10**18
N,M = map(int,input().split())
edge = [list(map(int,input().split())) for i in range(M)]
graph = [[] for _ in range(N)]
for e in edge:
graph[e[0]-1].append([e[1]-1,-e[2]])
dist = [INF for _ in range(N)]
dist[0] = 0
for _ in range(N):
flag = False
for node,g in enumerate(graph):
... |
s400463715 | p03722 | u073852194 | 1574207499 | Python | PyPy3 (2.4.0) | py | Runtime Error | 417 | 47576 | 932 | INF = 10**18
N,M = map(int,input().split())
edge = [list(map(int,input().split())) for i in range(M)]
graph = [[] for _ in range(N)]
for e in edge:
graph[e[0]-1].append([e[1]-1,-e[2]])
dist = [INF for _ in range(N)]
dist[0] = 0
for _ in range(N):
flag = False
for node,g in enumerate(graph):
... |
s166786574 | p03722 | u879870653 | 1574191242 | Python | Python (3.4.3) | py | Runtime Error | 2110 | 35588 | 507 | from scipy.sparse.csgraph import csgraph_from_dense, bellman_ford
mINF = -(10**16)
n,m = map(int,input().split())
A = [0]*m
B = [0]*m
C = [0]*m
for i in range(m) :
a, b, c = map(int,input().split())
A[i], B[i], C[i] = a-1, b-1, -c
graph = [[mINF]*n for i in range(n)]
for i in range(m) :
graph[A[i]][B[i]] =... |
s798063170 | p03722 | u476383383 | 1573311310 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 1331 | #include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCA... |
s597920466 | p03722 | u593590006 | 1571711078 | Python | Python (3.4.3) | py | Runtime Error | 2108 | 4876 | 2152 | # Python program to print all paths from a source to destination.
cnt=0
ans=0
from collections import defaultdict
from collections import Counter
def check(arr):
#print(arr)
ans=0
for i in range(1,len(arr)):
ans+=e[(arr[i-1],arr[i])]
# print(ans)
return ans
maxi=-10**1999
mini=10**9... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.