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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s583250148 | p03722 | u844789719 | 1545847777 | Python | Python (3.4.3) | py | Runtime Error | 26 | 3444 | 660 | import math
V, E = [int(_) for _ in input().split()]
G = {}
for i in range(V):
G[i] = {}
for _ in range(E):
s, t, c = [int(_) for _ in input().split()]
s -= 1 # 0を始点とする場合
t -= 1 # 0を始点とする場合
G[s][t] = -c
INF = math.inf
D = [INF] * V
D[0] = 0 # 0を始点とする場合
count = 0
while True:
count += 1
... |
s085535708 | p03722 | u064408584 | 1544504358 | Python | Python (3.4.3) | py | Runtime Error | 25 | 3700 | 446 | def BF(p,n,s):
inf=float("inf")
d=[inf for i in range(n)]
d[s-1]=0
for i in range(n+1):
for e in p:
if e[0]!=inf and d[e[1]-1]>d[e[0]-1]+e[2]:
d[e[1]-1] = d[e[0]-1] + e[2]
if i==n: return [0,'inf']
return list(map(lambda x:-x, d))
n,m=map(int, inpu... |
s472931314 | p03722 | u620868411 | 1544190385 | Python | Python (3.4.3) | py | Runtime Error | 184 | 12944 | 582 | # -*- coding: utf-8 -*-
inf = 10**9+1
n,m = map(int, input().split())
edge = [[inf for _ in range(n)] for _ in range(n)]
for _ in range(m):
a,b,c = map(int, input().split())
a -= 1
b -= 1
edge[a][b] = c
score = [inf for _ in range(n)]
def dfs(v):
for u in range(n):
if edge[v][u]<inf:
... |
s200107507 | p03722 | u099566485 | 1541617921 | Python | Python (3.4.3) | py | Runtime Error | 1370 | 3372 | 723 | #061-D
#v,Eは、頂点(vertex),辺(edge)の数
v,E=map(int,input().split())
e=[]
for i in range(E): #eの各要素は[始点,終点,コスト]
f,t,c=map(int,input().split())
e.append([f-1,t-1,-c])
d=[None for i in range(v)]
def lp(s,g): #sは始点、dに各頂点への最短距離が格納される
for i in range(v):
d[i]=float('INF')
d[s]=0
c=0
while c<v+1:
... |
s683214369 | p03722 | u099566485 | 1541617803 | Python | Python (3.4.3) | py | Runtime Error | 2103 | 3372 | 710 | #061-D
#v,Eは、頂点(vertex),辺(edge)の数
v,E=map(int,input().split())
e=[]
for i in range(E): #eの各要素は[始点,終点,コスト]
f,t,c=map(int,input().split())
e.append([f-1,t-1,-c])
d=[None for i in range(v)]
def lp(s,g): #sは始点、dに各頂点への最短距離が格納される
for i in range(v):
d[i]=float('INF')
d[s]=0
c=0
while c<v+1:
... |
s306103668 | p03722 | u785989355 | 1541187027 | Python | Python (3.4.3) | py | Runtime Error | 36 | 4316 | 2659 |
import queue
class Graph:
INF = 10**27+1
def __init__(self,v_num,is_directed = False):
self.is_directed = is_directed
self.v_num = v_num
self.E = []
self.v_s_list = [[] for i in range(self.v_num)]
def appendEdge(self,v1,v2,weight=1):
if max(v1,v2,self... |
s793461748 | p03722 | u368780724 | 1541156721 | Python | Python (3.4.3) | py | Runtime Error | 511 | 3188 | 627 | def inpl(): return [int(i) for i in input().split()]
N, M = inpl()
inf = float('inf')
path = [0 for _ in range(N)]
score = [-inf]*N
score[0] = 0
ans = 0
for i in range(M):
a, b, c = inpl()
path[i] = (a-1,b-1,c)
for i in range(N-1):
update = False
for na, nb, nc in path:
if score[na] != -inf an... |
s194615510 | p03722 | u170201762 | 1540680343 | Python | Python (3.4.3) | py | Runtime Error | 997 | 3316 | 626 | N,M = map(int,input().split())
edge = [0]*M
for i in range(M):
a,b,c=map(int,input().split())
a -= 1
b -= 1
c *= -1
edge[i] = (a,b,c)
inf = float('inf')
V = N
E = M
d = [inf]*V
d[0] = 0
for i in range(V):
update = False
for j in range(E):
From,To,cost = edge[j]
if d[From] !=... |
s086401953 | p03722 | u170201762 | 1540679386 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 541 | N,M = map(int,input().split())
edge = [0]*M
for i in range(M):
a,b,c=map(int,input().split())
a -= 1
b -= 1
c *= -1
edge[i] = (a,b,c)
inf = float('inf')
V = N
E = M
def shortest_path(s,d):
for i in range(V):
for j in range(E):
From,To,cost = edge[j]
if d[From] !=... |
s054320314 | p03722 | u098240946 | 1538323950 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 765 | inf = int(1e20)
node,edge = map(int,input().split())
ed = []
for e in range(edge):
ed.append(e[0]-1,e[1]-1,-e[2])
start = 0
goal = node-1
d = [inf for i in range(node)]
pre = [inf for i in range(node)]
d[start] = 0
for i in range(node):
update = False
for e in ed:
if d[e[0]] != inf and d[e[1]]>d... |
s740071805 | p03722 | u536113865 | 1537652371 | Python | Python (3.4.3) | py | Runtime Error | 25 | 3308 | 325 | ai = lambda: list(map(int, input().split()))
n,m = ai()
edge = []
for _ in range(m):
a,b,c = ai()
edge.append((a-1, b-1, -c))
import networkx as nx
G = nx.DiGraph()
G.add_weighted_edges_from(edge)
if nx.negative_edge_cycle(G):
print('inf')
else:
print(-nx.bellman_ford_path_length(G, source=0, target=n... |
s664412072 | p03722 | u536113865 | 1537652359 | Python | Python (3.4.3) | py | Runtime Error | 26 | 3308 | 325 | ai = lambda: list(map(int, input().split()))
n,m = ai()
edge = []
for _ in range(m):
a,b,c = ai()
edge.append((a-1, b-1, -c))
import networkx as nx
G = nx.DiGraph()
G.add_weighted_edges_from(edge)
if nx.negative_edge_cycle(G):
print('inf')
else:
print(-nx.bellman_ford_path_length(G, source=0, target=n... |
s603808922 | p03722 | u557171945 | 1536877628 | Python | PyPy3 (2.4.0) | py | Runtime Error | 325 | 46568 | 722 | INF = float('inf')
N,M = map(int,input().split())
edge = []
d = [INF]*N
d[0] = 0
negative = [False for i in range(N)]
for i in range(M):
a,b,c = map(int,input().split())
edge.append([a-1,b-1,-c])
for i in range(N):
for j in range(M):
if d[edge[j][0]]==INF:
continue
d[edge[j][1]]... |
s609529145 | p03722 | u620868411 | 1536543005 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 978 | # -*- coding: utf-8 -*-
inf = 10**50
n,m = map(int, input().split())
ea = []
eb = []
cost = []
for _ in range(m):
a,b,c = map(int, input().split())
a -= 1
b -= 1
ea.append(a)
eb.append(b)
cost.append(-c)
d = [inf for _ in range(n)]
d[0] = 0
for _ in range(n):
update = False
for i in r... |
s567931606 | p03722 | u439396449 | 1535824388 | Python | Python (3.4.3) | py | Runtime Error | 296 | 3820 | 1034 | from collections import defaultdict
N, M = map(int, input().split())
class Graph(object):
def __init__(self):
self.edges = defaultdict(list)
self.nodes = set()
def add_edge(self, src, dst, weight=1):
self.edges[src].append((dst, weight))
self.nodes.add(src)
self.nodes... |
s195160695 | p03722 | u439396449 | 1535823290 | Python | Python (3.4.3) | py | Runtime Error | 297 | 3820 | 1071 | from collections import defaultdict
from heapq import heappop, heappush
N, M = map(int, input().split())
class Graph(object):
def __init__(self):
self.edges = defaultdict(list)
self.nodes = set()
def add_edge(self, src, dst, weight=1):
self.edges[src].append((dst, weight))
se... |
s528463428 | p03722 | u439396449 | 1535822975 | Python | Python (3.4.3) | py | Runtime Error | 295 | 3820 | 1070 | from collections import defaultdict
from heapq import heappop, heappush
N, M = map(int, input().split())
class Graph(object):
def __init__(self):
self.edges = defaultdict(list)
self.nodes = set()
def add_edge(self, src, dst, weight=1):
self.edges[src].append((dst, weight))
se... |
s277304404 | p03722 | u439396449 | 1535821144 | Python | Python (3.4.3) | py | Runtime Error | 198 | 3820 | 1544 | from collections import defaultdict
from heapq import heappop, heappush
N, M = map(int, input().split())
class Graph(object):
def __init__(self):
self.edges = defaultdict(list)
self.nodes = set()
def add_edge(self, src, dst, weight=1):
self.edges[src].append((dst, weight))
se... |
s428861696 | p03722 | u439396449 | 1535820801 | Python | Python (3.4.3) | py | Runtime Error | 198 | 3820 | 1352 | from collections import defaultdict
from heapq import heappop, heappush
N, M = map(int, input().split())
class Graph(object):
def __init__(self):
self.edges = defaultdict(list)
self.nodes = set()
def add_edge(self, src, dst, weight=1):
self.edges[src].append((dst, weight))
se... |
s821815505 | p03722 | u439396449 | 1535819383 | Python | Python (3.4.3) | py | Runtime Error | 29 | 3820 | 1804 | from collections import defaultdict
from heapq import heappop, heappush
N, M = map(int, input().split())
class Graph(object):
def __init__(self):
self.graph = defaultdict(list)
self.nodes = set()
def __len__(self):
return len(self.graph)
def add_edge(self, src, dst, weight=1):
... |
s476892798 | p03722 | u690536347 | 1535616965 | Python | Python (3.4.3) | py | Runtime Error | 1921 | 3188 | 590 | n,m=map(int,input().split())
a,b,c=[None]*n,[None]*n,[None]*n
inf=float("inf")
d=[inf]*n
neg=[False]*n
d[0]=0
for i in range(m):
a[i],b[i],c[i]=map(int,input().split())
c[i]=-c[i]
for loop in range(n-1):
for i in range(m):
if d[a[i]-1]==inf:continue
if d[b[i]-1]>d[a[i]-1]+c[i]:
d[b[i]-1]=d[a[i]-1]... |
s177395554 | p03722 | u690536347 | 1535616390 | Python | Python (3.4.3) | py | Runtime Error | 1940 | 3188 | 631 | from heapq import heappush,heappop
n,m=map(int,input().split())
a,b,c=[None]*n,[None]*n,[None]*n
inf=float("inf")
d=[inf]*n
for i in range(m):
a[i],b[i],c[i]=map(int,input().split())
c[i]=-c[i]
d[0]=0
for loop in range(n-1):
for i in range(m):
if d[a[i]-1]==inf:continue
if d[b[i]-1]>d[a[i]-1]+c[i]:
... |
s021657604 | p03722 | u232852711 | 1533707228 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 877 | from math import inf
n, m = list(map(int, input().split()))
a, b, c = [], [], []
for _ in range(m):
abc = list(map(int, input().split()))
a.append(abc[0])
b.append(abc[1])
c.append(-abc[2]) # convert pos-neg
dist = [inf]*(n+1)
dist[1] = 0
for loop in range(n-1):
for i in range(m):
if dist[a... |
s824463487 | p03722 | u232852711 | 1533704786 | Python | Python (3.4.3) | py | Runtime Error | 31 | 3444 | 1012 | n, m = list(map(int, input().split()))
paths = {}
for _ in range(m):
a, b, c = list(map(int, input().split()))
if not a in paths.keys():
paths[a] = {b:c}
else:
paths[a][b] = c
# print(paths)
score = [None]*(n+1)
score[1] = 0
stack = [(k, [1]) for k in paths[1].keys()]
is_inf = False
while l... |
s521712185 | p03722 | u763034939 | 1527659813 | Python | Python (3.4.3) | py | Runtime Error | 1082 | 3316 | 623 | N, M = map(int, input().split())
edge = []
for i in range(M):
a,b,c = map(int, input().split())
edge.append((a-1,b-1, c))
point = [None] * N
point[0] = 0
for i in range(N):
for a,b,c in edge:
if point[a] is not None:
if point[b] is None:
point[b] = point[a] + c
... |
s621877224 | p03722 | u278479217 | 1527133825 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 599 | from math import inf
N, M = map(int, input().split())
edges = []
for j in range(M):
edges.append(list(map(int, input().split())))
d = [0] + ([-inf]*(N-1))
pred = [None] * N
for i in range(N-1):
for j in range(M):
u = edges[j][0]-1
v = edges[j][1]-1
w = edges[j][2]
if d[v] < d[... |
s258260401 | p03722 | u278479217 | 1527133707 | Python | PyPy3 (2.4.0) | py | Runtime Error | 166 | 38384 | 599 | from math import inf
N, M = map(int, input().split())
edges = []
for j in range(M):
edges.append(list(map(int, input().split())))
d = [0] + ([-inf]*(N-1))
pred = [None] * N
for i in range(N-1):
for j in range(M):
u = edges[j][0]-1
v = edges[j][1]-1
w = edges[j][2]
if d[v] < d[... |
s280741983 | p03722 | u010110540 | 1504794627 | Python | Python (3.4.3) | py | Runtime Error | 548 | 3316 | 631 | import sys
INF = float('inf')
def Bellmanford(n, edges, r): #r: 始点
d = [INF] * n
d[r] = 0
for i in range(n):
flag = False
for (u, v, c) in edges:
if d[u] != INF and d[u] + c < d[v]:
d[v] = d[u] + c
flag = True
if fl... |
s735187027 | p03722 | u602860891 | 1503675445 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3316 | 893 | import sys
N, M = list(map(int, input().split()))
a_list = list()
b_list = list()
c_list = list()
for _ in range(M):
a, b, c = list(map(int, input().split()))
a_list.append(a)
b_list.append(b)
c_list.append(-c)
inf = sys.maxsize
dist = [inf for _ in range(N)]
dist[0] = 0
for _ in range(N-1):
fo... |
s778778118 | p03722 | u451017206 | 1503121246 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 8264 | 601 | N, M = map(int,input().split())
tree = {}
for i in range(M):
a, b, c = map(int, input().split())
v= tree.get(a,[])
v.append([b, c])
tree[a] = v
m = []
def cost(v, c, visited):
if v in visited:
m.append(c)
if max(m) > 0:
print('inf')
exit()
return
... |
s209911109 | p03722 | u451017206 | 1503120001 | Python | Python (3.4.3) | py | Runtime Error | 96 | 8260 | 681 | N, M = map(int,input().split())
tree = {}
for i in range(M):
a, b, c = map(int, input().split())
v= tree.get(a,[])
v.append([b, c])
tree[a] = v
def has_loop(tree):
pass
m = []
def cost(v, c, visited):
if v in visited:
m.append(c)
if max(m) <= 0:
print(max(m))
... |
s163370971 | p03722 | u451017206 | 1503119707 | Python | Python (3.4.3) | py | Runtime Error | 96 | 8264 | 681 | N, M = map(int,input().split())
tree = {}
for i in range(M):
a, b, c = map(int, input().split())
v= tree.get(a,[])
v.append([b, c])
tree[a] = v
def has_loop(tree):
pass
m = []
def cost(v, c, visited):
if v in visited:
m.append(c)
if max(m) < 0:
print(max(m))
... |
s243633394 | p03722 | u451017206 | 1503119460 | Python | Python (3.4.3) | py | Runtime Error | 96 | 8260 | 661 | N, M = map(int,input().split())
tree = {}
for i in range(M):
a, b, c = map(int, input().split())
v= tree.get(a,[])
v.append([b, c])
tree[a] = v
def has_loop(tree):
pass
m = []
def cost(v, c, visited):
if v in visited:
if max(m) < 0:
print(max(m))
else:
... |
s929373660 | p03722 | u451017206 | 1503119144 | Python | Python (3.4.3) | py | Runtime Error | 99 | 8260 | 594 | N, M = map(int,input().split())
tree = {}
for i in range(M):
a, b, c = map(int, input().split())
v= tree.get(a,[])
v.append([b, c])
tree[a] = v
def has_loop(tree):
pass
m = []
def cost(v, c, visited):
if v in visited:
print('inf')
exit()
b = tree.get(v, None)
if b is N... |
s041923037 | p03722 | u451017206 | 1503118820 | Python | Python (3.4.3) | py | Runtime Error | 95 | 8256 | 561 | N, M = map(int,input().split())
tree = {}
for i in range(M):
a, b, c = map(int, input().split())
v= tree.get(a,[])
v.append([b, c])
tree[a] = v
def has_loop(tree):
pass
m = []
def cost(v, c, visited):
if v in visited:
print('inf')
exit()
global m
b = tree[v]
if len... |
s834532775 | p03722 | u846372029 | 1499059055 | Python | Python (3.4.3) | py | Runtime Error | 1451 | 3188 | 926 | # Score Attack
n,m = list(map(int, input().split()))
a = []
b = []
c = []
for i in range(n):
ia,ib,ic = list(map(int, input().split()))
a.append(ia)
b.append(ib)
c.append(-ic)
import sys
INF = sys.maxsize
dist = [INF for i in range(n)]
dist[0] = 0
for l in range(n-1):
for i in range(m):
... |
s243355541 | p03722 | u871999682 | 1498765979 | Python | Python (2.7.6) | py | Runtime Error | 11 | 2696 | 847 | def max_score(edge,N):
inf =float("inf")
w = [-inf for i in range(int(N)+1)]
w[1] = 0;
while True:
update = False
negative = False
for e in edge:
if e[0] > e[1] and e[2]>0:
#update = True
negative = True
... |
s754513087 | p03722 | u985443069 | 1497632291 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3188 | 1370 | import sys
sys.stdin = open('d1.in')
inf = 10 ** 20
def solve(n, m, weights):
score = [-inf] * n
score[0] = 0
pred = [-1] * n
for step in range(n):
for edge, c in weights.items():
a, b = edge
if score[b] < score[a] + c:
score[b] = score[a] + c
... |
s106638731 | p03722 | u654824270 | 1496494657 | Python | Python (3.4.3) | py | Runtime Error | 26 | 3572 | 513 |
N, M = map(int, input().split())
score_list = [-float("inf")] * (N + 1)
score_list[1] = 0
m_list = []
for i in range(M):
m_list.append(list(map(int, input().split())))
m_list.sort(key=lambda x: x[0])
score_keep = 0
for count in [0, 1]:
for x in m_list:
if score_list[x[0]] + x[2] > score_list[x[1]]:
... |
s146941785 | p03722 | u327466606 | 1496279372 | Python | Python (3.4.3) | py | Runtime Error | 2109 | 22224 | 651 | N,M = map(int, input().split())
from scipy.sparse import lil_matrix
from scipy.sparse.csgraph import depth_first_order,bellman_ford
import numpy as np
from time import process_time as timer
G = lil_matrix((N,N), dtype='i4')
for i in range(M):
a,b,c = map(int, input().split())
G[a-1,b-1] = -c
# remove nodes unre... |
s477637246 | p03722 | u327466606 | 1496279151 | Python | Python (3.4.3) | py | Runtime Error | 419 | 26280 | 622 | N,M = map(int, input().split())
from scipy.sparse import lil_matrix
from scipy.sparse.csgraph import *
import numpy as np
from time import process_time as timer
G = lil_matrix((N,N), dtype='i4')
for i in range(M):
a,b,c = map(int, input().split())
G[a-1,b-1] = -c
# remove nodes unreachable from goal or start
n1... |
s979379092 | p03722 | u340781749 | 1495744769 | Python | Python (3.4.3) | py | Runtime Error | 599 | 4284 | 1130 | import sys
n, m = map(int, input().split())
sys.setrecursionlimit(n)
edges = [set() for _ in range(n)]
for _ in range(m):
a, b, c = map(int, input().split())
edges[a - 1].add((b - 1, c))
NINF = float('-inf')
dists = [NINF for _ in range(n)]
dists[0] = 0
def trace(v, updated):
updated[v] = True
for b... |
s232600555 | p03722 | u340781749 | 1495744700 | Python | Python (3.4.3) | py | Runtime Error | 624 | 4284 | 1093 | n, m = map(int, input().split())
edges = [set() for _ in range(n)]
for _ in range(m):
a, b, c = map(int, input().split())
edges[a - 1].add((b - 1, c))
NINF = float('-inf')
dists = [NINF for _ in range(n)]
dists[0] = 0
def trace(v, updated):
updated[v] = True
for b, c in edges[v]:
if not updat... |
s021977181 | p03722 | u820351940 | 1495490224 | Python | Python (3.4.3) | py | Runtime Error | 691 | 3828 | 588 | n, m = map(int, input().split())
abc = [list(map(int, input().split())) for x in range(m)]
nodes = [[] for x in range(n + 1)]
for a, b, c in abc:
nodes[a].append([a, b, -c])
costs = [None for x in range(n + 1)]
costs[1] = 0
flg = True
for i in range(n):
for node in nodes[1:]:
for a, b, c in node:
... |
s832951816 | p03722 | u820351940 | 1495488700 | Python | Python (3.4.3) | py | Runtime Error | 558 | 3700 | 586 | n, m = map(int, input().split())
abc = [list(map(int, input().split())) for x in range(m)]
nodes = [[] for x in range(n + 1)]
for a, b, c in abc:
nodes[a].append([a, b, c])
costs = [None for x in range(n + 1)]
costs[1] = 0
flg = True
for i in range(n):
for node in nodes[1:]:
for a, b, c in node:
... |
s612311333 | p03722 | u667084803 | 1494840291 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 627 | import sys
N,M=map(int, input().split())
a=[]
b=[]
c=[]
for m in range (0,M):
A,B,C=map(int, input().split() )
a+=[A]
b+=[B]
c+=[C]
V=[0]+[-10**12]*(N-1)# iに到達するときの最大得点
for n in range(N-1):
for m in range(M):
u=a[m]
v=b[m]
if V[b[m]-1]<V[a[m]-1]+c[m]:#共に有限の時はやる
V[b[m]-1]=V[a[m]-1]+c[m]
m... |
s525222628 | p03722 | u667084803 | 1494840253 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 626 | mport sys
N,M=map(int, input().split())
a=[]
b=[]
c=[]
for m in range (0,M):
A,B,C=map(int, input().split() )
a+=[A]
b+=[B]
c+=[C]
V=[0]+[-10**12]*(N-1)# iに到達するときの最大得点
for n in range(N-1):
for m in range(M):
u=a[m]
v=b[m]
if V[b[m]-1]<V[a[m]-1]+c[m]:#共に有限の時はやる
V[b[m]-1]=V[a[m]-1]+c[m]
mo... |
s251379953 | p03722 | u667084803 | 1494840240 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 634 | mport sys
N,M=map(int, input().split())
a=[]
b=[]
c=[]
for m in range (0,M):
A,B,C=map(int, input().split() )
a+=[A]
b+=[B]
c+=[C]
V=[0]+[-10**12]*(N-1)# iに到達するときの最大得点
for n in range(N-1):
for m in range(M):
u=a[m]
v=b[m]
if V[b[m]-1]<V[a[m]-1]+c[m]:#共に有限の時はやる
V[b[m]-1]=V[a[m]-1]+c[m]
mo... |
s123082856 | p03722 | u466826467 | 1494818887 | Python | Python (3.4.3) | py | Runtime Error | 859 | 3628 | 1096 | class Edge:
def __init__(self, fromE, to, cost):
self.fromE = fromE
self.to = to
self.cost = cost
def min_path(_s):
d[_s] = 0
while True:
update = False
for i in range(0, N):
edge = abc[i]
if d[edge.fromE] != float("inf") and d[edge.to] > d[e... |
s474674604 | p03722 | u079701009 | 1494818303 | Python | Python (2.7.6) | py | Runtime Error | 11 | 2696 | 680 | # Bellman-Ford
n, m = map(int, raw_bellman-input().split())
a, b, c = [], [], []
for i in xrange(m):
at, bt, ct = map(int, raw_input().split())
a.append(at - 1)
b.append(bt - 1)
c.append(ct)
# step1 : initialize
point = [-1e9 * m - 1] * n
point[0] = 0
pointl = [None] * n
# step2 : relaxation
for i in xr... |
s816722333 | p03722 | u976162616 | 1494791756 | Python | PyPy3 (2.4.0) | py | Runtime Error | 171 | 38384 | 1353 | from collections import defaultdict
MAX_N = 10 ** 3 + 10
MAX_M = 2 * (10 ** 3) + 1
INF = -(10 ** 100)
def bfs(graph, N, M):
que = []
que.append([0, 0])
visited = defaultdict(list)
result = INF
while (len(que) > 0):
now = que[0]
que.pop(0)
pos = now[0]
cost = now[1]
... |
s350519342 | p03722 | u976162616 | 1494790625 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2108 | 67420 | 1372 | from collections import defaultdict
MAX_N = 10 ** 3 + 10
MAX_M = 2 * (10 ** 3) + 1
INF = -(10 ** 100)
def bfs(graph, N, M):
que = []
que.append([0, 0])
visited = defaultdict(list)
result = INF
while (len(que) > 0):
now = que[0]
que.pop(0)
pos = now[0]
cost = now[1]
... |
s865431036 | p03722 | u976162616 | 1494790502 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1668 | 52696 | 1368 | from collections import defaultdict
MAX_N = 10 ** 3 + 10
MAX_M = 2 * (10 ** 3) + 1
INF = -(10 ** 100)
def bfs(graph, N, M):
que = []
que.append([0, 0])
visited = defaultdict(list)
result = INF
while (len(que) > 0):
now = que[0]
que.pop(0)
pos = now[0]
cost = now[1]
... |
s447290128 | p03722 | u976162616 | 1494790302 | Python | PyPy3 (2.4.0) | py | Runtime Error | 797 | 48744 | 1372 | from collections import defaultdict
MAX_N = 10 ** 3 + 10
MAX_M = 2 * (10 ** 3) + 1
INF = -(10 ** 100)
def bfs(graph, N, M):
que = []
que.append([0, 0])
visited = defaultdict(list)
result = INF
while (len(que) > 0):
now = que[0]
que.pop(0)
pos = now[0]
cost = now[1]
... |
s138219180 | p03722 | u125205981 | 1494786673 | Python | Python (3.4.3) | py | Runtime Error | 82 | 4308 | 559 | def main():
N, M = map(int, input().split())
global abc
abc = [None] * M
for i in range(M):
abc[i] = tuple(map(int, input().split()))
global point
point = -1000000000 * 2000
point = dfs(0, N, 0)
print(point)
def dfs(s, e, p):
global point
if abc[s][0] == 1:
p = 0... |
s557718139 | p03722 | u997053690 | 1494763105 | Python | Python (2.7.6) | py | Runtime Error | 417 | 12036 | 845 | def calc_weight(pw, weights, max_n):
new_pw = [[]] * max_n
k = 0
for p, w in pw:
if p == len(weights) - 1:
new_pw[k] = [p, w]
k += 1
li = weights[p]
non_zero = [[i, x] for i, x in enumerate(li) if x != 0]
for j, x in non_zero:
new_pw[k] = [... |
s999869111 | p03722 | u341926204 | 1494745865 | Python | Python (3.4.3) | py | Runtime Error | 62 | 7796 | 1017 | def d():
n, m = map(int, input().split())
node = []
for i in range(m):
ai, bi, ci = map(int, input().split())
node.append([ai, bi, ci])
node = sorted(node, key=lambda n: n[1])
node = sorted(node, key=lambda n: n[0])
route = []
score = None
for i in node:
ai, bi, ... |
s191227545 | p03722 | u341926204 | 1494745469 | Python | Python (3.4.3) | py | Runtime Error | 51 | 3388 | 935 | def d():
n, m = map(int, input().split())
node = []
for i in range(m):
ai, bi, ci = map(int, input().split())
node.append([ai, bi, ci])
node = sorted(node, key=lambda n: n[1])
node = sorted(node, key=lambda n: n[0])
route = []
score = None
for i in node:
ai, bi, ... |
s548037065 | p03722 | u341926204 | 1494745400 | Python | Python (3.4.3) | py | Runtime Error | 157 | 17848 | 931 | def d():
n, m = map(int, input().split())
node = []
for i in range(m):
ai, bi, ci = map(int, input().split())
node.append([ai, bi, ci])
node = sorted(node, key=lambda n: n[1])
node = sorted(node, key=lambda n: n[0])
route = []
score = None
for i in node:
ai, bi, ... |
s332010213 | p03722 | u382748202 | 1494740747 | Python | Python (3.4.3) | py | Runtime Error | 1667 | 4356 | 1854 | import sys
def set_enable_goal(cur_node, back_paths, enable_goal):
if cur_node in back_paths:
for next_node in back_paths[cur_node]:
if enable_goal[next_node - 1] == 0:
enable_goal[next_node - 1] = 1
set_enable_goal(next_node, back_paths, enable_goal)
N, M = ma... |
s191518292 | p03722 | u382748202 | 1494740380 | Python | Python (3.4.3) | py | Runtime Error | 1225 | 4352 | 1660 | import sys
def set_enable_goal(cur_node, back_paths, enable_goal):
if cur_node in back_paths:
for next_node in back_paths[cur_node]:
if enable_goal[next_node - 1] == 0:
enable_goal[next_node - 1] = 1
set_enable_goal(next_node, back_paths, enable_goal)
N, M = ma... |
s340342120 | p03722 | u341926204 | 1494737153 | Python | Python (3.4.3) | py | Runtime Error | 150 | 17848 | 917 | def d():
n, m = map(int, input().split())
node = []
for i in range(m):
ai, bi, ci = map(int, input().split())
node.append([ai, bi, ci])
sorted(node, key=lambda n: n[1])
sorted(node, key=lambda n: n[0])
route = []
score = None
for i in node:
ai, bi, ci = i
... |
s268250800 | p03722 | u820351940 | 1494735695 | Python | Python (3.4.3) | py | Runtime Error | 690 | 3700 | 653 | n, m = map(int, input().split())
abc = [list(map(int, input().split())) for x in range(m)]
nodemap = [[] for x in range(n + 1)]
for a, b, c in abc:
nodemap[a].append([a, b, c])
changed = False
calced = [None for x in range(n + 1)]
calced[1] = 0
for i in range(n - 1):
changed = False
for nodes in node... |
s677657255 | p03722 | u820351940 | 1494735612 | Python | Python (3.4.3) | py | Runtime Error | 607 | 3700 | 609 | n, m = map(int, input().split())
abc = [list(map(int, input().split())) for x in range(m)]
nodemap = [[] for x in range(n + 1)]
for a, b, c in abc:
nodemap[a].append([a, b, c])
changed = False
calced = [None for x in range(n + 1)]
calced[1] = 0
for i in range(n - 1):
changed = False
for nodes in node... |
s781310985 | p03722 | u667084803 | 1494734386 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 3316 | 736 | import sys
N,M=map(int, input().split())
a=[]
b=[]
c=[]
for m in range (0,M):
A,B,C=map(int, input().split() )
a+=[A]
b+=[B]
c+=[C]
V=[0]*N# iに到達するときの最大得点
moji=[1]+[0]*(N-1)#infなら0をかえす
for n in range(N-1):
for m in range(M):
u=a[m]
v=b[m]
if moji[a[m]-1]:#共に有限の時はやる
if moji[b[m]-1]:
... |
s767185561 | p03722 | u846694620 | 1494733298 | Python | Python (3.4.3) | py | Runtime Error | 31 | 4084 | 3198 | import collections
import heapq
import math
class GraphLoopException(Exception):
pass
class WeightedDigraph:
def __init__(self):
self.__vertices = set()
self.__edges = collections.defaultdict(list)
self.__weights = {}
@property
def vertices(self):
return self.__verti... |
s934796557 | p03722 | u327466606 | 1494732897 | Python | Python (3.4.3) | py | Runtime Error | 394 | 3828 | 1187 | N,M = map(int, input().split())
from collections import defaultdict
E = []
for i in range(M):
a,b,c = map(int, input().split())
a,b = a-1, b-1
E += [(a,b,c)]
def reachable_vertices(neighbor, s):
V = set()
V.add(s)
stack=[s]
while stack:
v = stack.pop()
for u in neighbor[v]:
if u not in V:... |
s513460557 | p03722 | u663710122 | 1494732620 | Python | Python (3.4.3) | py | Runtime Error | 2103 | 3440 | 758 | import math
INF = float("inf")
V, E = map(int, input().split())
es = []
for _ in range(E):
a, b, c = map(int, input().split())
es.append([a-1, b-1, -c])
d = [INF] * V
d[1] = 0
for _ in range(V - 1):
updated = False
for e in es:
if math.isinf(d[e[0]]):
continue
if d[e[1]]... |
s290757576 | p03722 | u667084803 | 1494732613 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 841 | import sys
N,M=map(int, input().split())
a=[]
b=[]
c=[]
for m in range (0,M):
A,B,C=map(int, input().split() )
a+=[A]
b+=[B]
c+=[C]
V=[0]*N# iに到達するときの最大得点
moji=[1]+[0]*(N-1)#infなら0をかえす
for n in range(N-1):
for m in range(M):
u=a[m]
v=b[m]
if moji[a[m]-1]:#共に有限の時はやる
if moji[b[m]-1]:
... |
s745650643 | p03722 | u663710122 | 1494732578 | Python | Python (3.4.3) | py | Runtime Error | 1211 | 3444 | 727 | import math
INF = float("inf")
V, E = map(int, input().split())
es = []
for _ in range(E):
a, b, c = map(int, input().split())
es.append([a-1, b-1, -c])
d = [INF] * V
d[1] = 0
updated = False
for _ in range(V - 1):
for e in es:
if math.isinf(d[e[0]]):
continue
if d[e[1]] > d... |
s499320871 | p03722 | u382748202 | 1494731950 | Python | Python (3.4.3) | py | Runtime Error | 107 | 35932 | 1000 | def trans(cur, prev_paths, score, goal_score, paths, N):
# inf check
if cur in prev_paths:
return 'inf'
if cur == N:
goal_score = score
if not cur in paths:
return goal_score
nodes = paths[cur]
score_updated = False
for n, s in nodes:
new_score = score + s
... |
s338510901 | p03722 | u926678805 | 1494731828 | Python | Python (3.4.3) | py | Runtime Error | 134 | 4472 | 752 | # coding: utf-8
n,m=map(int,input().split())
score={}
muki={}
kita={}
for i in range(1,n+1):
score[i]=0
muki[i]=[(-1,0)]
kita[i]=0
for i in range(m):
a,b,c=map(int,input().split())
if muki[a][0][0]==-1:
muki[a]=[(b,c)]
else:
muki[a].append((b,c))
def heiro(g,moto):
for n ... |
s451552160 | p03722 | u667084803 | 1494731466 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 797 | import sys
N,M=map(int, input().split())
a=[]
b=[]
c=[]
for m in range (0,M):
A,B,C=map(int, input().split() )
a+=[A]
b+=[B]
c+=[C]
V=[0]*N# iに到達するときの最大得点
moji=[1]+[0]*(N-1)#infなら0をかえす
for n in range(N-1):
for m in range(M):
u=a[m]
v=b[m]
if moji[a[m]-1]:#共に有限の時はやる
if moji[b[m]-1]:
... |
s524518100 | p03722 | u382748202 | 1494731442 | Python | Python (3.4.3) | py | Runtime Error | 107 | 35912 | 920 | def trans(cur, prev_paths, score, goal_score, paths, N):
# inf check
if cur in prev_paths:
return 'inf'
if cur == N:
goal_score = score
if not cur in paths:
return goal_score
nodes = paths[cur]
for n, s in nodes:
new_score = score + s
new_prev_paths = dic... |
s571627750 | p03722 | u330205771 | 1494731440 | Python | Python (2.7.6) | py | Runtime Error | 114 | 66284 | 989 | N, M = map(int, raw_input().split())
a = []
b = []
c = []
for i in range(M):
temp0, temp1, temp2= map(int, raw_input().split())
a.append(temp0)
b.append(temp1)
c.append(temp2)
def search(path, target, score):
result = []
result_score = []
for p in range(len(path)):
for i in range(M... |
s368760105 | p03722 | u463836923 | 1494731235 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 3444 | 1886 | #coding=UTF-8
mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
A=[]
B=[]
Cost=[]
for idx in range(0,M,1):
mozir=input()
hyo=mozir.split(' ')
A.append(int(hyo[0])-1)
B.append(int(hyo[1])-1)
Cost.append(int(hyo[2]))
#先ず得点が正になるループを探す
eipap=False
for idx in range(0,N,1):
tansa... |
s057607552 | p03722 | u926678805 | 1494730999 | Python | Python (3.4.3) | py | Runtime Error | 135 | 4460 | 499 | # coding: utf-8
n,m=map(int,input().split())
score={}
muki={}
kita={}
for i in range(1,n+1):
score[i]=0
muki[i]=[(-1,0)]
kita[i]=0
for i in range(m):
a,b,c=map(int,input().split())
if muki[a][0][0]==-1:
muki[a]=[(b,c)]
else:
muki[a].append((b,c))
def heiro(g,moto):
... |
s357366889 | p03722 | u817142576 | 1494730543 | Python | Python (2.7.6) | py | Runtime Error | 28 | 4152 | 843 | def update_score_dfs(target):
global graph, visited, scores
visited[target] = 1
for node, score in graph[target].items():
if scores[target] + score > scores[node]:
scores[node] = scores[target] + score
for nextnode in graph[target].keys():
if visited[nextnode] == 1:
... |
s421807187 | p03722 | u926678805 | 1494730039 | Python | Python (3.4.3) | py | Runtime Error | 138 | 4468 | 778 | # coding: utf-8
n,m=map(int,input().split())
data=[]
dic={}
muki={}
kita={}
for i in range(1,n+1):
dic[i]=0
muki[i]=[(-1,0)]
kita[i]=0
def heiroCheck(moto,m):
for i in muki[moto]:
if i[0]!=m:
if i[0]!=-1:
heiroCheck(i[0],m)
else:
print('inf')
... |
s550230558 | p03722 | u402629484 | 1494729994 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 1513 | from math import inf
N, M = map(int, input().split())
l = [[] for _ in range(N)]
for _ in range(M):
a, b, c = map(int, input().split())
l[b - 1].append((a - 1, c))
def a_max(a, b):
if a is None:
return b
elif b is None:
return a
else:
return max(a, b)
def contains(q, t):
... |
s170541803 | p03722 | u486231815 | 1494729864 | Python | Python (3.4.3) | py | Runtime Error | 2108 | 4376 | 1127 | import sys
def solve(node, sc, ps, inf_check, goal_cnt):
global inf
if goal_cnt == 0 and sc > max_score[node]:
max_score[node] = sc
if node == N:
goal_cnt += 1
if inf_check:
inf = True
if goal_cnt >= 2:
return
for n in path[node]:
if n in ... |
s223479567 | p03722 | u382748202 | 1494729560 | Python | Python (3.4.3) | py | Runtime Error | 78 | 4304 | 610 | def trans(cur, prev, score, paths, N):
# inf check
if cur in prev_paths:
return 'inf'
if cur == N and not cur in paths:
return score
nodes = paths[cur]
for n, s in nodes:
score += s
prev_paths[cur] = 1
return trans(n, prev_paths, score, paths, N)
N, M = map... |
s683388941 | p03722 | u314057689 | 1494729508 | Python | Python (3.4.3) | py | Runtime Error | 40 | 11624 | 828 | from collections import defaultdict as dd
def main():
N, M = map(int, input().split())
MAP = [[0]*N for x in range(N)]
E = []
for m in range(M):
a,b,c = map(int, input().split())
MAP[a-1][b-1] = c
E.append((a-1,b-1,c))
dp = [-float('inf')]*N
dp[0] = 0
updated = set(... |
s762139033 | p03722 | u558528117 | 1494729484 | Python | Python (3.4.3) | py | Runtime Error | 106 | 10612 | 2435 | import sys
from collections import defaultdict
sys.setrecursionlimit(100000)
def has_loop_f(now, path_dic, weight_dic, visited_path):
next_cand = path_dic[now]
if len(next_cand) == 0:
return (False, ([], 0))
# sys.stderr.write(str(next_cand))
# sys.stderr.write("\n")
for next_v in next_ca... |
s648761519 | p03722 | u402629484 | 1494729476 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 1360 | from math import inf
N, M = map(int, input().split())
l = [[] for _ in range(N)]
for _ in range(M):
a, b, c = map(int, input().split())
l[b - 1].append((a - 1, c))
def a_max(a, b):
if a is None:
return b
elif b is None:
return a
else:
return max(a, b)
def contains(q, t):
... |
s702575267 | p03722 | u531959175 | 1494729407 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 68060 | 922 | import math
def int_input():
line = input()
return [int(x) for x in line.split()]
n, m = int_input()
graph = {}
for i in range(n):
graph[i+1] = {}
for i in range(m):
a, b, c = int_input()
graph[a][b] = c
def walk(graph, current, stack, acc_score, has_loop):
if graph[current]:
for de... |
s553730685 | p03722 | u033407970 | 1494729218 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 17368 | 890 | def dstar(use, i):
connect = ver[i]
use.append(i)
for k in range(n):
if connect[k] != 0.5:
if k in use:
if weigth[i] + connect[k] <= weigth[k]:
if k == n-1:
print('inf')
exit()
else:
... |
s305176898 | p03722 | u531959175 | 1494729111 | Python | Python (3.4.3) | py | Runtime Error | 160 | 68036 | 921 | import math
def int_input():
line = input()
return [int(x) for x in line.split()]
n, m = int_input()
graph = {}
for i in range(n):
graph[i+1] = {}
for i in range(m):
a, b, c = int_input()
graph[a][b] = c
def walk(graph, current, stack, acc_score, has_loop):
if graph[current]:
for de... |
s450944148 | p03722 | u926678805 | 1494729084 | Python | Python (3.4.3) | py | Runtime Error | 83 | 4444 | 672 | # coding: utf-8
n,m=map(int,input().split())
data=[]
dic={}
muki={}
kita={}
for i in range(1,n+1):
dic[i]=0
muki[i]=[(-1,0)]
kita[i]=0
for i in range(m):
a,b,c=map(int,input().split())
if muki[a][0]!=(-1,0):
muki[a].append((b,c))
else:
muki[a]=[(b,c)]
def check(moto):
for p ... |
s103777356 | p03722 | u382748202 | 1494728991 | Python | Python (3.4.3) | py | Runtime Error | 78 | 4260 | 620 | def trans(cur, prev, score, paths, N):
# inf check
if cur in paths:
nodes = paths[cur]
for n, s in nodes:
if prev == n:
return 'inf'
if cur == N:
return score
nodes = paths[cur]
for n, s in nodes:
score += s
return trans(n, cur, sc... |
s658872385 | p03722 | u846694620 | 1494728960 | Python | Python (3.4.3) | py | Runtime Error | 31 | 4076 | 2382 | import collections
import heapq
import math
# python 3 only!!!
import collections
import math
class Graph:
def __init__(self):
self.vertices = set()
self.successors = collections.defaultdict(list)
self.weights = {}
def add_vertex(self, label):
self.vertices.add(label)
de... |
s126507877 | p03722 | u558528117 | 1494728866 | Python | Python (3.4.3) | py | Runtime Error | 108 | 10604 | 2189 | import sys
from collections import defaultdict
sys.setrecursionlimit(100000)
def has_loop_f(now, path_dic, weight_dic, visited_path):
next_cand = path_dic[now]
if len(next_cand) == 0:
return (False, ([], 0))
# sys.stderr.write(str(next_cand))
# sys.stderr.write("\n")
for next_v in next_ca... |
s535773498 | p03722 | u531959175 | 1494728725 | Python | Python (3.4.3) | py | Runtime Error | 162 | 68036 | 921 | import math
def int_input():
line = input()
return [int(x) for x in line.split()]
n, m = int_input()
graph = {}
for i in range(n):
graph[i+1] = {}
for i in range(m):
a, b, c = int_input()
graph[a][b] = c
max_score = 0
def walk(graph, current, stack, acc_score, has_loop):
has_loop = False
... |
s886394081 | p03722 | u254343015 | 1494728469 | Python | Python (2.7.6) | py | Runtime Error | 16 | 2696 | 797 | N,M = map(int,raw_input().split())
W = [['inf' for j in range(N)] for i in range(N)]
y = ['inf' for i in range(N)]
y_t = ['inf' for i in range(N)]
y[0] = 0
y_t[0] = 0
for i in range(N):
W[i][i]=0
for i in range(M):
a,b,c=map(int,raw_input().split())
W[a-1][b-1] = c
flag = False
for i in range(N):
f... |
s261743874 | p03722 | u033407970 | 1494728464 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 17368 | 872 | def dstar(use, i):
connect = ver[i]
use.append(i)
for k in range(n):
if connect[k] != 0.5:
if k in use:
if weigth[i] + k > 0:
if k == n-1:
print('inf')
exit()
else:
... |
s753466502 | p03722 | u846694620 | 1494727749 | Python | Python (3.4.3) | py | Runtime Error | 30 | 4076 | 2549 | import collections
import heapq
import math
class WeightedDigraph:
def __init__(self):
self.vertices = set()
self.successors = collections.defaultdict(list)
self.weights = {}
def add_vertex(self, label):
self.vertices.add(label)
def add_edge(self, begin, end, weight):
... |
s777134548 | p03722 | u275145490 | 1494727549 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 83 | 6 5
1 2 -1000000000
2 3 -1000000000
3 4 -1000000000
4 5 -1000000000
5 6 -1000000000 |
s950401185 | p03722 | u379559362 | 1494727543 | Python | Python (3.4.3) | py | Runtime Error | 135 | 4856 | 427 | n, m = map(int, input().split())
l = [[0, 0, 0]]
for i in range(m):
a, b, c = map(int, input().split())
l.append([a, b, c])
edge = [- (10 ** 15)] * (n + 1)
ans = - (10 ** 15)
edge[1] = 0
def func(now):
if now == n:
return edge[n]
f_l = filter(lambda x: x[0] == now, l)
for j in f_l:
... |
s978802233 | p03722 | u275145490 | 1494727336 | Python | Python (3.4.3) | py | Runtime Error | 78 | 4140 | 565 | read = lambda: map(int, input().split())
n, m = read()
g = [list() for i in range(n + 2)]
for i in range(m):
a, b, c = read()
g[b].append((a, c))
g[1].append((0, 0))
g[n + 1].append((n, 0))
top = []
def dfs(v):
if was[v]: return
was[v] = 1
for u, w in g[v]: dfs(u)
top.append(v)
was = [0] * (n + ... |
s599936792 | p03722 | u657357805 | 1494726785 | Python | Python (3.4.3) | py | Runtime Error | 110 | 4140 | 642 |
N,M = [int(x) for x in input().split()]
A=[]
B=[]
C=[]
for i in range(M):
a,b,c = [int(x) for x in input().split()]
A.append(a)
B.append(b)
C.append(c+10**9+1)
nodes= [0]*(N+1)
max_score=0
max_score_node=0
def count(node,score,l):
global max_score
global max_score_node
if node==N:
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.