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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s868457179 | p02361 | u825008385 | 1523455912 | Python | Python3 | py | Runtime Error | 0 | 0 | 1247 | from memory_profiler import profile
# Single Source Shortest Path
infty = 99999
[vertex, edge, r] = list(map(int, input("").split()))
D = [[infty for j in range(vertex)] for i in range(vertex)]
for i in range(edge):
data = list(map(int, input("").split()))
D[data[0]][data[1]] = data[2]
@profile
def Dijkstra(r... |
s501486847 | p02361 | u825008385 | 1523455991 | Python | Python3 | py | Runtime Error | 20 | 5612 | 1202 | # Single Source Shortest Path
infty = 99999
[vertex, edge, r] = list(map(int, input("").split()))
D = [[infty for j in range(vertex)] for i in range(vertex)]
for i in range(edge):
data = list(map(int, input("").split()))
D[data[0]][data[1]] = data[2]
def Dijkstra(root, n):
visited_order = 0
label = [0... |
s593960884 | p02361 | u825008385 | 1523546392 | Python | Python3 | py | Runtime Error | 20 | 5620 | 1419 | # Single Source Shortest Path
infty = 99999
[vertex, edge, r] = list(map(int, input("").split()))
dict_r = {}
for i in range(vertex):
dict_r[(r,i)] = infty
dict_c = {}
for i in range(edge):
data = list(map(int, input("").split()))
if int(data[0]) == r:
dict_r[(data[0],data[1])] = int(data[2])
... |
s321194101 | p02361 | u167493070 | 1523758349 | Python | Python3 | py | Runtime Error | 20 | 5748 | 1439 | import sys
import heapq
def dfs(u,s,target, vs):
vs[u] = 1
if(u == target):
global h
heapq.heappush(h,s)
return
for j in range(e):
if(e_1[j] == u):
if(vs[e_2[j]] != 1):
count = s + e_w[j]
print(s,e_2[j],vs)
dfs(e_2... |
s555319078 | p02361 | u167493070 | 1523758432 | Python | Python3 | py | Runtime Error | 0 | 0 | 1478 | import sys
import heapq
def dfs(u,s,target, vs):
vs[u] = 1
if(u == target):
global h
heapq.heappush(h,s)
return
for j in range(e):
if(e_1[j] == u):
if(vs[e_2[j]] != 1):
count = s + e_w[j]
print(s,e_2[j],vs)
dfs(e_2... |
s989608808 | p02361 | u167493070 | 1523759330 | Python | Python3 | py | Runtime Error | 0 | 0 | 1315 | import sys
import heapq
def dfs(u,s,target, vs):
vs[u] = 1
if(u == target):
global h
heapq.heappush(h,s)
return
for j in range(e):
if(e_1[j] == u):
if(vs[e_2[j]] != 1):
count = s + e_w[j]
print(s,e_2[j],vs)
dfs(e_2... |
s856725892 | p02361 | u167493070 | 1523760376 | Python | Python3 | py | Runtime Error | 0 | 0 | 465 | INF = 9999999999999999999
d = [INF for i in range(v)]
d[r] = 0
heapq.heappush(v_q,(0,r))
while(len(v_q) != 0):
cost,u = heapq.heappop(v_q)
if(cost > d[u]):
continue
for j in range(e):
if(u == e_1[j]):
alt = cost+e_w[j]
if(d[e_2[j]] > alt):
d[e_2[j]] = ... |
s872744914 | p02361 | u167493070 | 1528102894 | Python | Python3 | py | Runtime Error | 0 | 0 | 660 | import sys
from collections import deque
v,e,r=map(int, input().split());
e_1=[0]*e;
e_2=[0]*e;
e_w=[0]*e;
for i in range(e):
e_1[i], e_2[i], e_w[i] = map(int, input().split());
v_q=[];
INF = 9999999999999999999
d = [INF for i in range(v)]
d[r] = 0
heapq.heappush(v_q,(0,r))
while(len(v_q) != 0):
cost,u = h... |
s038825156 | p02361 | u167493070 | 1528102909 | Python | Python3 | py | Runtime Error | 0 | 0 | 641 | import sys
from heapq
v,e,r=map(int, input().split());
e_1=[0]*e;
e_2=[0]*e;
e_w=[0]*e;
for i in range(e):
e_1[i], e_2[i], e_w[i] = map(int, input().split());
v_q=[];
INF = 9999999999999999999
d = [INF for i in range(v)]
d[r] = 0
heapq.heappush(v_q,(0,r))
while(len(v_q) != 0):
cost,u = heapq.heappop(v_q)
... |
s139384417 | p02361 | u089116225 | 1529340734 | Python | Python3 | py | Runtime Error | 0 | 0 | 450 | V,E,r = map(int, input().split())
edges = []
for _ in range(E):
tmp = [int(x) for x in input().split()]
edges.append(tmp)
d = [float('inf') for _ in range(V)]
d[r] = 0
for _ in range(V-1):
count = 0
for x in edges:
s,t,d = x
if d[t] > d[s] + d:
count += 1
d[t] =... |
s227200387 | p02362 | u871901071 | 1404086451 | Python | Python3 | py | Runtime Error | 0 | 0 | 857 | import sys
def shortestPath(graph, s):
n = len(graph)
dist = [inf for _ in range(n)]
dist[s] = 0
for i in range(n):
for u in range(n):
for v, cost in graph[u]:
newDist = dist[u] + cost
if dist[u] != inf and newDist < dist[v]:
if i... |
s374339174 | p02362 | u567380442 | 1427694806 | Python | Python3 | py | Runtime Error | 0 | 0 | 858 | class exist_negative_cycle(Exception):
pass
def bellman_ford(g, size, start=0):
d = [float('inf')] * size
d[start] = 0
for _ in range(size):
for u in g:
for length, v in g[u]:
if d[v] > d[u] + length:
d[v] = d[u] + length
for u in g:
... |
s727560565 | p02362 | u442472098 | 1433241362 | Python | Python3 | py | Runtime Error | 0 | 0 | 548 | #!/usr/bin/env python3
from math import isinf
V, E, r = map(int, input().split())
vertices = [float('inf')] * V
vertices[r] = 0
edges = []
for i in range(E):
s, t, d = map(int, input().split())
edges.append((s, t, d))
for i in range(V - 1):
for s, t, d in edges:
if vertices[t] > vertices[s] + d:
... |
s903592549 | p02362 | u966364923 | 1451569884 | Python | Python3 | py | Runtime Error | 0 | 0 | 783 | V, E, root = map(int, input().split())
visited = [False] * V
nodes = [[] for i in range(V)]
cost = [[] for i in range(V)]
for i in range(E):
s, t, d = map(int, input().split())
nodes[s].append(t)
cost[s].append(d)
dist = [float('inf')] * V
dist[root] = 0
negative_cycle = False
for k in range(V):
for ... |
s746998718 | p02362 | u352394527 | 1528071924 | Python | Python3 | py | Runtime Error | 20 | 5600 | 848 |
INF = 10 ** 20
v_num, e_num, r = map(int, input().split())
dist_lst = [INF for _ in range(v_num)]
edges_lst = [[] for _ in range(e_num)]
negative_cycle_flag = False
for _ in range(e_num):
s, t, dist = map(int, input().split())
edges_lst[s].append((dist, t))
dist_lst[r] = 0
for _ in range(v_num):
for v in ran... |
s655507519 | p02363 | u397460030 | 1468758454 | Python | Python3 | py | Runtime Error | 50 | 7840 | 1491 | import heapq
def solve(num_v ,graph_data): # dict -> [[arr]]
solution = []
for i in range(num_v):
solution.append(partial_solve(i, graph_data))
return solution
def partial_solve(source,graph_data):
heap = [(0,source)]
partial_solution = [float("inf") for _ in range(4)]
while heap:
... |
s759868690 | p02363 | u397460030 | 1468758592 | Python | Python3 | py | Runtime Error | 20 | 7828 | 1509 | import heapq
def solve(num_v ,graph_data): # dict -> [[arr]]
solution = []
for i in range(num_v):
solution.append(partial_solve(i, num_v, graph_data))
return solution
def partial_solve(source, num_v,graph_data):
heap = [(0,source)]
partial_solution = [float("inf") for _ in range(num_v)]
... |
s487215530 | p02363 | u397460030 | 1469103786 | Python | Python3 | py | Runtime Error | 30 | 7784 | 1411 | def print_solve(ans):
if "negative" in ans:
print("NEGATIVE CYCLE")
else:
for l in ans:
for c in l[:-1]:
if c == float("inf"):
print("INF",end=" ")
else:
print(c,end=" ")
print(l[-1])
def solve(graph... |
s828578532 | p02363 | u022407960 | 1480178506 | Python | Python3 | py | Runtime Error | 30 | 7712 | 1318 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
from sys import stdin
def generate_adj_table(v_table):
for each in v_table:
start, end, weight = map(int, each)
init_adj_table[start][end] = weight
return init_adj_table
def floyd():
for k in _range:
for i in _range:
if ... |
s236929037 | p02363 | u798803522 | 1486974937 | Python | Python3 | py | Runtime Error | 0 | 0 | 903 | from collections import defaultdict
vertice,edge = map(int,input().split(" "))
cost = [[0 if m == n else float("inf") for n in range(vertice)] for m in range(vertice)]
link = defaultdict(dict)
weight = defaultdict(dict)
for e in range(edge):
i,j,w = map(int,input().split(""))
link[i] = link.get(i,set()) | {j}... |
s809618441 | p02363 | u798803522 | 1486974978 | Python | Python3 | py | Runtime Error | 0 | 0 | 904 | from collections import defaultdict
vertice,edge = map(int,input().split(" "))
cost = [[0 if m == n else float("inf") for n in range(vertice)] for m in range(vertice)]
link = defaultdict(dict)
weight = defaultdict(dict)
for e in range(edge):
i,j,w = map(int,input().split(""))
link[i] = link.get(i,set()) | {j}... |
s410898245 | p02363 | u798803522 | 1507967565 | Python | Python3 | py | Runtime Error | 0 | 0 | 892 | from collections import defaultdict
vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
cost_dp = [[float("inf") if n != m else 0 for n in range(vertices)] for m in range(vertices)]
for e in range(edges):
v1, v2, weight = (int(n) for n in input().split(" "))
connect[v1].append([v2... |
s037692375 | p02363 | u798803522 | 1507967691 | Python | Python3 | py | Runtime Error | 0 | 0 | 888 | from collections import defaultdict
vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
cost_dp = [[float("inf") if n != m else 0 for n in range(vertices)] for m in range(vertices)]
for e in range(edges):
v1, v2, weight = (int(n) for n in input().split(" "))
connect[v1].append([v2... |
s220587712 | p02363 | u146816547 | 1510482876 | Python | Python | py | Runtime Error | 0 | 0 | 986 | def main():
INF = int(1e12)
G = [[0 for i in range(101)] for j in range(101)];
v, e = map(int, raw_input().split())
for i in range(v):
for j in range(v):
if i == j:
G[i][j] = 0
else:
G[i][j] = INF
for i in range(e):
s, t, ... |
s251032147 | p02363 | u146816547 | 1510482918 | Python | Python | py | Runtime Error | 0 | 0 | 931 | def main():
INF = int(1e12)
G = [[0 for i in range(101)] for j in range(101)];
v, e = map(int, raw_input().split())
for i in range(v):
for j in range(v):
if i == j:
G[i][j] = 0
else:
G[i][j] = INF
for i in range(e):
s, ... |
s560650720 | p02364 | u131811591 | 1531698670 | Python | Python3 | py | Runtime Error | 0 | 0 | 1106 | import sys
from union_find import UnionFind
from operator import attrgetter
class Kruskal:
class Edge:
def __init__(self, u, v, cost):
self.u, self.v, self.cost = u, v, cost
def __lt__(self, another):
return self.cost < another.cost
def __init__(self, node_size):
... |
s896088028 | p02364 | u629780968 | 1545454370 | Python | Python3 | py | Runtime Error | 0 | 0 | 610 | n = int(input())
m = [[-1 for i in range (n)] for j in range(n)]
d = [0]+ [2000]* (n-1)
isVisited = [False] * n
for i in range(n):
nums = list(map(int, input().split()))
for j in range(n):
m[i][j] = nums[j]
# def prim_mst(n):
def prim_mst(n):
while True:
mincost = 2000
for i in range(n):
if... |
s047730740 | p02364 | u629780968 | 1545454935 | Python | Python3 | py | Runtime Error | 0 | 0 | 851 | n = int(input())
m = [[-1 for i in range(n)] for j in range(n)] #お隣さんへのコストを保存(この中から最小を探す)
v = set()
v.add(0)
for i in range(n): #隣接の辺のコストを入力
nums = list(map(int, input().split()))
for j in range(n):
m[i][j] = nums[j]
def prim_mst(n):
isVisited = [False] * n
d = [0] + [2001] * (n-1) #TとV-Tのを繋ぐ最小辺の重み... |
s290488990 | p02364 | u943441430 | 1559194638 | Python | Python3 | py | Runtime Error | 20 | 5664 | 962 | from heapq import heappush, heappop
line = input()
v, e = list(map(int, line.split()))
edge = {}
for _ in range(0, e):
line = input()
s, t, w = list(map(int, line.split()))
if s not in edge:
edge[s] = [[t, w]]
else:
edge[s] += [[t, w]]
if t not in edge:
edge[t] = [[s, w]]
... |
s096901846 | p02364 | u686180487 | 1559355770 | Python | Python3 | py | Runtime Error | 0 | 0 | 544 | # -*- coding: utf-8 -*-
V, E = list(map(int, input().split()))
weight = []
for i in range(E):
s, t, w = list(map(int, input().split()))
weight.append((s,t,w))
weight.sort(key = lambda x: x[2])
parent = [i for i in range(V)]
def find(x):
if parent[x] == x:
return x
else:
return find(parent[x])
def u... |
s229423508 | p02364 | u797673668 | 1455720460 | Python | Python3 | py | Runtime Error | 20 | 7744 | 562 | import heapq
nv, ne = map(int, input().split())
edges = [set() for _ in range(nv)]
while ne:
s, t, w = map(int, input().split())
edges[s].add((w, t))
edges[t].add((w, s))
ne -= 1
cost = 0
queue = list(edges[0])
heapq.heapify(queue)
visited = [False] * nv
visited[0] = True
while True:
edge_cost, ... |
s915397639 | p02364 | u766163292 | 1459318669 | Python | Python3 | py | Runtime Error | 0 | 0 | 1428 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import collections
import heapq
AdjacentVertex = collections.namedtuple("AdjacentVertex", "vertex cost")
INF = 2 ** 31 - 1
NO_VERTEX = -1
# Prim?????§??????0?????????????°???¨?????¨????±???????
def compute_mst_prim(max_v, adj_list):
# pred[u]?????????u???????????¨... |
s039775401 | p02364 | u798803522 | 1487230887 | Python | Python3 | py | Runtime Error | 30 | 7900 | 984 | from collections import defaultdict
import heapq
vertices,edges = map(int,input().split(" "))
link = defaultdict(dict)
weight = defaultdict(dict)
for e in range(edges):
source,target,w = map(int,input().split(" "))
link[source] = link.get(source,set()) | {target}
link[target] = link.get(target,set()) | {s... |
s295276899 | p02364 | u798803522 | 1487233494 | Python | Python3 | py | Runtime Error | 0 | 0 | 1038 | from collections import defaultdict
import heapq
vertices,edges = map(int,input().split(" "))
link = defaultdict(dict)
weight = defaultdict(dict)
way = [float("inf")] * vertices
for e in range(edges):
source,target,w = map(int,input().split(" "))
link[source] = link.get(source,set()) | {target}
link[target... |
s147338420 | p02364 | u798803522 | 1487238471 | Python | Python3 | py | Runtime Error | 0 | 0 | 1214 | from collections import defaultdict
import heapq
def aaa()
vertices,edges = map(int,input().split(" "))
link = defaultdict(dict)
weight = defaultdict(dict)
way = [float("inf")] * vertices
for e in range(edges):
source,target,w = map(int,input().split(" "))
link[source] = link.get(sou... |
s242314772 | p02364 | u035108350 | 1500340429 | Python | Python3 | py | Runtime Error | 0 | 0 | 4955 |
class Node:
def __init__(self):
pass
class Edge:
def __init__(self,edge,cost=1):
self.node_from=edge[0]
self.node_to=edge[1]
self.cost=cost
def add_node(self,node):
self.nodes.append(node)
class myGraph:
def __init__(self):
self.adj={}
self.no... |
s952166354 | p02364 | u035108350 | 1500340475 | Python | Python3 | py | Runtime Error | 0 | 0 | 4955 |
class Node:
def __init__(self):
pass
class Edge:
def __init__(self,edge,cost=1):
self.node_from=edge[0]
self.node_to=edge[1]
self.cost=cost
def add_node(self,node):
self.nodes.append(node)
class myGraph:
def __init__(self):
self.adj={}
self.no... |
s458518479 | p02364 | u035108350 | 1500340581 | Python | Python3 | py | Runtime Error | 0 | 0 | 4957 |
class Node:
def __init__(self):
pass
class Edge:
def __init__(self,edge,cost=1):
self.node_from=edge[0]
self.node_to=edge[1]
self.cost=cost
def add_node(self,node):
self.nodes.append(node)
class myGraph:
def __init__(self):
self.adj={}
self.no... |
s447300525 | p02364 | u035108350 | 1500340632 | Python | Python3 | py | Runtime Error | 0 | 0 | 4957 |
class Node:
def __init__(self):
pass
class Edge:
def __init__(self,edge,cost=1):
self.node_from=edge[0]
self.node_to=edge[1]
self.cost=cost
def add_node(self,node):
self.nodes.append(node)
class myGraph:
def __init__(self):
self.adj={}
self.no... |
s626351835 | p02364 | u510829608 | 1501308057 | Python | Python3 | py | Runtime Error | 0 | 0 | 1482 | import array
import collections
import heapq
AdjacentVertex = collections.namedtuple('AdjacentVertex', 'vertex cost')
INF = 2 ** 31 - 1
NO_VERTEX = -1
#Prim?????§??????0?????????????°???¨?????¨(minimum spanning tree????±???????)
def compute_mst_prim(max_v, adj_list):
# pred[u]?????????u???????????¨??????????????... |
s451716904 | p02364 | u510829608 | 1501308096 | Python | Python3 | py | Runtime Error | 0 | 0 | 1482 | import array
import collections
import heapq
AdjacentVertex = collections.namedtuple('AdjacentVertex', 'vertex cost')
INF = 2 ** 31 - 1
NO_VERTEX = -1
#Prim?????§??????0?????????????°???¨?????¨(minimum spanning tree????±???????)
def compute_mst_prim(max_v, adj_list):
# pred[u]?????????u???????????¨??????????????... |
s231016768 | p02364 | u510829608 | 1501308123 | Python | Python3 | py | Runtime Error | 0 | 0 | 1482 | import array
import collections
import heapq
AdjacentVertex = collections.namedtuple('AdjacentVertex', 'vertex cost')
INF = 2 ** 31 - 1
NO_VERTEX = -1
#Prim?????§??????0?????????????°???¨?????¨(minimum spanning tree????±???????)
def compute_mst_prim(max_v, adj_list):
# pred[u]?????????u???????????¨??????????????... |
s507452906 | p02364 | u510829608 | 1501308638 | Python | Python3 | py | Runtime Error | 0 | 0 | 2942 | import array
import collections
import heapq
AdjacentVertex = collections.namedtuple("AdjacentVertex", "vertex cost")
INF = 2 ** 31 - 1
NO_VERTEX = -1
# Prim?????§??????0?????????????°???¨?????¨????±???????
def compute_mst_prim(max_v, adj_list):
# pred[u]?????????u???????????¨???????????????????????¨???
pred... |
s189812025 | p02364 | u881590806 | 1502609381 | Python | Python3 | py | Runtime Error | 30 | 7992 | 832 | from collections import defaultdict
INF = 9999999999999999999999999999
def spanning_tree(G):
n = len(G)
T = {}
added = set()
min_c = INF
for i in G:
for j in G[i]:
if G[i][j] < min_c:
min_c = G[i][j]
min_e = (i, j)
T[min_e] = min_c
added.add(min_e[0])
added.add(min_e[1])
whi... |
s767565344 | p02364 | u510829608 | 1504102928 | Python | Python3 | py | Runtime Error | 0 | 0 | 584 | mport heapq
from collections import defaultdict
INF = float('inf')
V, E = map(int, input().split())
Adj_list = defaultdict(set)
for i in range(E):
s, t, w = map(int, input().split())
Adj_list[s].add((t, w))
Adj_list[t].add((s, w))
def prim(x):
d = [INF] * x
d[0] = 0
hq = [(0,0)]
... |
s050725167 | p02364 | u798803522 | 1507974416 | Python | Python3 | py | Runtime Error | 0 | 0 | 758 | from collections import defaultdict
import heapq
vertices, edges = (int(n) for n in input().split(" "))
conn = defaultdict(set)
weight = defaultdict(dict())
for i in range(edges):
v1, v2, w = (int(n) for n in input().split(" "))
conn[v1] |= {v2}
conn[v2] |= {v1}
weight[v1][v2] = w
weight[v2][v1] = w... |
s021693790 | p02365 | u797673668 | 1455910205 | Python | Python3 | py | Runtime Error | 30 | 7904 | 2089 | import heapq
nv, ne, r = map(int, input().split())
in_edges = {v: set() for v in range(nv)}
out_edges = {v: set() for v in range(nv)}
while ne:
s, t, w = map(int, input().split())
in_edges[t].add((w, s))
out_edges[s].add((w, t))
ne -= 1
def chu_liu_edmond(vertices):
global in_edges, out_edges, n... |
s476496161 | p02365 | u685815919 | 1475030188 | Python | Python | py | Runtime Error | 20 | 6488 | 1198 | def edmond(V, paths, root):
mins = [(10**18, -1)]*V
for s,t,w in paths:
mins[t] = min(mins[t], (w,s))
mins[r] = (-1, -1)
group = [0]*V
comp = [0]*V
cnt = 0
used = [0]*V
for v in xrange(V):
if not used[v]:
chain = []
cur = v
while not used[cur] and cur != -1:
chain.appe... |
s217883813 | p02365 | u072053884 | 1484492190 | Python | Python3 | py | Runtime Error | 30 | 7860 | 1750 | # Acceptance of input
import sys
file_input = sys.stdin
v_num, e_num, r = map(int, file_input.readline().split())
G = [[] for i in range(v_num)]
import heapq
for line in file_input:
s, t, w = map(int, line.split())
if t != r:
heapq.heappush(G[t], [w, s, t])
# Edmonds' algorithm
def find_cycle(in... |
s747186568 | p02365 | u035108350 | 1500340750 | Python | Python3 | py | Runtime Error | 0 | 0 | 4215 | class Node:
def __init__(self):
pass
class Edge:
def __init__(self,edge,cost=1):
self.node_from=edge[0]
self.node_to=edge[1]
self.cost=cost
def add_node(self,node):
self.nodes.append(node)
class myGraph:
def __init__(self):
self.adj={}
self.nod... |
s070147456 | p02366 | u967553879 | 1556715855 | Python | Python3 | py | Runtime Error | 30 | 7140 | 1313 | from collections import deque
def dfs(current, prev):
global time
# node currentを訪問した直後の処理
ord[current] = time
low[current] = time
time += 1
color[current] = BLACK
for next in G[current]:
if color[next] == WHITE:
# node currentからnode nextへ訪問する直前の処理
parent[n... |
s207467058 | p02366 | u567380442 | 1428131860 | Python | Python3 | py | Runtime Error | 50 | 7544 | 1368 | def dfs(u, prev, visited, lowest, parent, prenum):
# ????????? u ????¨????????????´????????????
visited |= {u}
prenum[u] = len(visited)
lowest[u] = len(visited)
for v in g[u]:
if v not in visited:
# ????????? u ??????????????? v ????¨????????????´????????????
parent... |
s949682410 | p02366 | u567380442 | 1428139037 | Python | Python3 | py | Runtime Error | 0 | 0 | 1113 | from sys import stdin
readline = stdin.readline
v, e = map(int, readline().split())
from collections import defaultdict
g = defaultdict(list)
for _ in range(e):
s, t = map(int, readline().split())
g[s].append(t)
g[t].append(s)
visited = set()
lowest = [None] * v
parent = [None] * v
prenum = [None] * ... |
s885290037 | p02366 | u567380442 | 1428140177 | Python | Python3 | py | Runtime Error | 0 | 0 | 1103 | from sys import stdin
readline = stdin.readline
v, e = map(int, readline().split())
from collections import defaultdict
g = defaultdict(list)
for _ in range(e):
s, t = map(int, readline().split())
g[s].append(t)
g[t].append(s)
visited = set()
lowest = [None] * v
parent = [None] * v
prenum = [None] * ... |
s036233960 | p02366 | u106851363 | 1444544678 | Python | Python3 | py | Runtime Error | 0 | 0 | 3268 | __author__ = 'zhewang711'
class Graph:
def __init__(self):
self.vertices = 0
self.outgoing = {}
self.root_cnt = 0
# self.incoming = {}
self.result = []
def insert_vertice(self):
self.vertices += 1
self.outgoing[self.vertices - 1] = []
# self.inco... |
s299166673 | p02366 | u106851363 | 1444551595 | Python | Python3 | py | Runtime Error | 0 | 0 | 3221 | __author__ = 'zhewang711'
class Graph:
def __init__(self):
self.vertices = 0
self.outgoing = {}
self.root_cnt = 0
# self.incoming = {}
self.result = []
def insert_vertice(self):
self.vertices += 1
self.outgoing[self.vertices - 1] = []
# self.inco... |
s562581919 | p02366 | u106851363 | 1444551993 | Python | Python3 | py | Runtime Error | 70 | 8752 | 3266 | __author__ = 'zhewang711'
class Graph:
def __init__(self):
self.vertices = 0
self.outgoing = {}
self.root_cnt = 0
# self.incoming = {}
self.result = set()
def insert_vertice(self):
self.vertices += 1
self.outgoing[self.vertices - 1] = []
# self.i... |
s774779117 | p02366 | u797673668 | 1461573976 | Python | Python3 | py | Runtime Error | 50 | 8964 | 898 | n, m = map(int, input().split())
edges = [set() for _ in range(n)]
for _ in range(m):
s, t = map(int, input().split())
edges[s].add(t)
edges[t].add(s)
prenum = [None] * n
parent = [None] * n
lowest = [None] * n
counter = 0
def dfs(cur, prev):
global counter
prenum[cur] = lowest[cur] = counter
... |
s463524665 | p02366 | u894114233 | 1461738300 | Python | Python | py | Runtime Error | 0 | 0 | 536 | def dfs(s,p):
global V,color
color[s]=1
for i in V[s] :
if color[i]==0 and i!=p:
dfs(i,p)
color[s]=2
def AP():
global V,ap,n,color
for i in xrange(n):
color=[0]*n
dfs(V[i][0],i)
color[i]=2
print color
if color!=[2]*n:
ap.ap... |
s534227465 | p02366 | u894114233 | 1461738330 | Python | Python | py | Runtime Error | 0 | 0 | 516 | def dfs(s,p):
global V,color
color[s]=1
for i in V[s] :
if color[i]==0 and i!=p:
dfs(i,p)
color[s]=2
def AP():
global V,ap,n,color
for i in xrange(n):
color=[0]*n
dfs(V[i][0],i)
color[i]=2
if color!=[2]*n:
ap.append(i)
n,e=map(int... |
s590812376 | p02366 | u894114233 | 1461738980 | Python | Python | py | Runtime Error | 750 | 7104 | 595 | def dfs(s,p,color):
color[s]=1
for i in V[s] :
if color[i]==0 and i!=p:
dfs(i,p,color)
color[s]=2
def AP():
for i in xrange(n):
color=[0]*n
dfs(V[i][0],i,color)
color[i]=2
if color!=[2]*n:
ap.append(i)
n,e=map(int,raw_input().split())
ap=... |
s802953858 | p02366 | u894114233 | 1461739837 | Python | Python | py | Runtime Error | 30 | 6464 | 729 | import sys
sys.setrecursionlimit(10*6)
def dfs(s,p,color):
color[s]=1
for i in V[s] :
if color[i]==0 and i!=p:
dfs(i,p,color)
color[s]=2
def AP():
for i in xrange(vn):
if V[i]!=[]:
color=[0]*vn
dfs(V[i][0],i,color)
color[i]=2
i... |
s649288766 | p02366 | u022407960 | 1480319923 | Python | Python3 | py | Runtime Error | 30 | 8756 | 1808 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 4
0 1
1 2
2 3
3 4
output:
1
2
3
"""
from sys import stdin
UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2
def generate_adj_table(_v_info):
for v_detail in _v_info:
v_from, v_to = map(int, v_detail)
init_adj_table[v_from].append(v_to... |
s963184012 | p02366 | u022407960 | 1480320046 | Python | Python3 | py | Runtime Error | 50 | 8800 | 1808 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 4
0 1
1 2
2 3
3 4
output:
1
2
3
"""
from sys import stdin
UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2
def generate_adj_table(_v_info):
for v_detail in _v_info:
v_from, v_to = map(int, v_detail)
init_adj_table[v_from].append(v_to... |
s572881673 | p02366 | u022407960 | 1480321663 | Python | Python3 | py | Runtime Error | 0 | 0 | 1922 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 4
0 1
1 2
2 3
3 4
output:
1
2
3
"""
from sys import stdin
UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2
def generate_adj_table(_v_info):
for v_detail in _v_info:
v_from, v_to = map(int, v_detail)
init_adj_table[v_from].append(v_to... |
s864056130 | p02366 | u022407960 | 1480321700 | Python | Python3 | py | Runtime Error | 20 | 8792 | 1858 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 4
0 1
1 2
2 3
3 4
output:
1
2
3
"""
from sys import stdin
UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2
def generate_adj_table(_v_info):
for v_detail in _v_info:
v_from, v_to = map(int, v_detail)
init_adj_table[v_from].append(v_to... |
s591469860 | p02366 | u022407960 | 1480324495 | Python | Python3 | py | Runtime Error | 0 | 0 | 1900 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 4
0 1
1 2
2 3
3 4
output:
1
2
3
"""
import sys
sys.setrecursionlimit(int(3e6))
UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2
def generate_adj_table(_v_info):
for v_detail in _v_info:
v_from, v_to = map(int, v_detail)
init_adj_tabl... |
s807469391 | p02366 | u022407960 | 1481632984 | Python | Python3 | py | Runtime Error | 40 | 10452 | 1551 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 4
0 1
1 2
2 3
3 4
output:
1
2
3
"""
import sys
sys.setrecursionlimit(int(1e4))
def dfs_Tarjan(current):
global timer
children = 0
visited[current] = True
disc[current] = low[current] = timer
timer += 1
for adj in adj_table[curren... |
s265991570 | p02366 | u400336986 | 1487447782 | Python | Python3 | py | Runtime Error | 0 | 0 | 809 | def dfs(v, tm):
dts[v] = est[v] = tm
child = 0
for i in range(nv):
if adj[v][i]:
if parents[i] is None:
child += 1
parents[i] = v
dfs(i, tm + 1)
est[v] = min(est[v], est[i])
if parents[v] is None and child ... |
s024721865 | p02366 | u400336986 | 1487447981 | Python | Python3 | py | Runtime Error | 160 | 16596 | 856 | def dfs(v, tm):
visited[v] = True
dts[v] = est[v] = tm
child = 0
for i in range(nv):
if adj[v][i]:
if not visited[i]:
child += 1
parents[i] = v
dfs(i, tm + 1)
est[v] = min(est[v], est[i])
if parents[v] ... |
s227607133 | p02366 | u881590806 | 1490960152 | Python | Python | py | Runtime Error | 0 | 0 | 1221 | def dfs(G,s,p,prenum,T,parents):
if len(G[s]) == 0: return p
T[s] = set()
prenum[s] = p
for c in G[s]:
if c in T: continue
p = dfs(G,c,p+1,prenum,T,parents)
T[s].add(c)
T[c].add(s)
parents[c] = s
return p
def find(G):
points = []
lowest = {}
pr... |
s584254139 | p02366 | u881590806 | 1490960203 | Python | Python | py | Runtime Error | 0 | 0 | 1218 | def dfs(G,s,p,prenum,T,parents):
if len(G[s]) == 0: return p
T[s] = set()
prenum[s] = p
for c in G[s]:
if c in T: continue
p = dfs(G,c,p+1,prenum,T,parents)
T[s].add(c)
T[c].add(s)
parents[c] = s
return p
def find(G):
points = []
lowest = {}
prenu... |
s974969402 | p02366 | u881590806 | 1490961371 | Python | Python | py | Runtime Error | 20 | 8120 | 1154 | def dfs(G,s,p,prenum,T,parents,lowest):
T[s] = set()
prenum[s] = p
lowest[s] = p
if len(G[s]) == 0: return p
for c in G[s]:
if c in T:
if lowest[s] > prenum[c]:
lowest[s] = prenum[c]
else:
p = dfs(G,c,p+1,prenum,T,parents,lowest)
T[... |
s494780311 | p02366 | u603049633 | 1496896569 | Python | Python3 | py | Runtime Error | 30 | 8780 | 1027 | V,E = map(int, input().split())
#??£??\??????????????????
A = [[] for i in range(V)]
for i in range(E):
s,t = map(int, input().split())
A[s].append(t)
A[t].append(s)
#?????????????¨???????
prenum = [None for i in range(V)]
#DFS???????????????????????????
parent = [None for i in range(V)]
#?????????????... |
s337982752 | p02366 | u426534722 | 1501019833 | Python | Python3 | py | Runtime Error | 30 | 8952 | 939 | from sys import stdin
import sys
n, m = map(int, stdin.readline().split())
edges = [set() for _ in range(n)]
for _ in [0] * m:
s, t = map(int, stdin.readline().split())
edges[s].add(t)
edges[t].add(s)
prenum = [None] * n
parent = [None] * n
lowest = [None] * n
counter = 0
def dfs(cur, prev):
global coun... |
s674001603 | p02366 | u426534722 | 1501019883 | Python | Python3 | py | Runtime Error | 30 | 8908 | 928 | from sys import stdin
n, m = map(int, stdin.readline().split())
edges = [set() for _ in range(n)]
for _ in [0] * m:
s, t = map(int, stdin.readline().split())
edges[s].add(t)
edges[t].add(s)
prenum = [None] * n
parent = [None] * n
lowest = [None] * n
counter = 0
def dfs(cur, prev):
global counter
pre... |
s867639661 | p02366 | u426534722 | 1501020047 | Python | Python3 | py | Runtime Error | 30 | 8520 | 773 | import sys
def dfs(v, tm):
dts[v] = est[v] = tm + 1
child = 0
for i in adj[v]:
if est[i] == float('inf'):
child += 1
parents[i] = v
dfs(i, tm + 1)
est[v] = min(est[v], est[i])
if parents[v] is None and child > 1: aps[v] = True
... |
s237376507 | p02366 | u881590806 | 1504195663 | Python | Python3 | py | Runtime Error | 60 | 9364 | 780 | prenum = {}
lowest = {}
parent = {}
visited = set()
def dfs(G, u, t):
prenum[u] = t
lowest[u] = t
visited.add(u)
for v in G[u]:
if v not in visited:
dfs(G, v, t+1)
lowest[u] = min(lowest[u], lowest[v])
parent[v] = u
else:
lowest[u] = min(lowest[u], prenum[v])
def solve(G):
df... |
s410774057 | p02366 | u260980560 | 1507995564 | Python | Python3 | py | Runtime Error | 0 | 0 | 893 | def get_articulation_points(G, N, start=0):
v_min = [0]*N; order = [None]*N
result = []; count = 0
def dfs(v, prev):
nonlocal count
r_min = order[v] = count
fcnt = 0; p_art = 0
count += 1
for w in G[v]:
if w == prev:
continue
if... |
s254297228 | p02366 | u260980560 | 1507996420 | Python | Python3 | py | Runtime Error | 60 | 8860 | 957 |
def get_articulation_points(G, N, start=0):
v_min = [0]*N; order = [None]*N
result = []; count = 0
def dfs(v, prev):
nonlocal count
r_min = order[v] = count
fcnt = 0; p_art = 0
count += 1
for w in G[v]:
if w == prev:
continue
i... |
s145514849 | p02366 | u798803522 | 1508055253 | Python | Python3 | py | Runtime Error | 20 | 7968 | 1229 | from collections import defaultdict
def seq():
a = 1
while True:
yield a
a += 1
def dfs(here, went, connect, discovery, low, answer, seq):
went |= {here}
discovery[here] = low[here] = next(seq)
child = 0
for con in connect[here]:
if con not in went:
parent[c... |
s471486340 | p02366 | u798803522 | 1508055838 | Python | Python3 | py | Runtime Error | 80 | 9096 | 1267 | from collections import defaultdict
def seq():
a = 1
while True:
yield a
a += 1
def dfs(here, went, connect, discovery, low, answer, seq):
went |= {here}
discovery[here] = low[here] = next(seq)
child = 0
for con in connect[here]:
if con not in went:
parent[c... |
s236368384 | p02366 | u519227872 | 1508058831 | Python | Python3 | py | Runtime Error | 80 | 9296 | 883 | from collections import defaultdict
V, E = map(int, input().split())
G = defaultdict(list)
T = defaultdict(list)
for i in range(E):
s,t = map(int, input().split())
G[s].append(t)
G[t].append(s)
prenum = [float('inf')] * V
lowest = [float('inf')] * V
parent = [None] * V
visited = [False] * V
def dfs(g,s,c=... |
s575416220 | p02366 | u519227872 | 1508059074 | Python | Python3 | py | Runtime Error | 70 | 11012 | 943 | from collections import defaultdict
import sys
sys.setrecursionlimit(2*sys.getrecursionlimit())
V, E = map(int, input().split())
G = defaultdict(list)
T = defaultdict(list)
for i in range(E):
s,t = map(int, input().split())
G[s].append(t)
G[t].append(s)
prenum = [float('inf')] * V
lowest = [float('inf')] *... |
s365409982 | p02366 | u519227872 | 1508059097 | Python | Python3 | py | Runtime Error | 60 | 10916 | 943 | from collections import defaultdict
import sys
sys.setrecursionlimit(3*sys.getrecursionlimit())
V, E = map(int, input().split())
G = defaultdict(list)
T = defaultdict(list)
for i in range(E):
s,t = map(int, input().split())
G[s].append(t)
G[t].append(s)
prenum = [float('inf')] * V
lowest = [float('inf')] *... |
s010245125 | p02366 | u519227872 | 1508059120 | Python | Python3 | py | Runtime Error | 60 | 11012 | 943 | from collections import defaultdict
import sys
sys.setrecursionlimit(5*sys.getrecursionlimit())
V, E = map(int, input().split())
G = defaultdict(list)
T = defaultdict(list)
for i in range(E):
s,t = map(int, input().split())
G[s].append(t)
G[t].append(s)
prenum = [float('inf')] * V
lowest = [float('inf')] *... |
s923190449 | p02366 | u662418022 | 1519735513 | Python | Python3 | py | Runtime Error | 30 | 7052 | 1172 | # -*- coding: utf-8 -*-
if __name__ == '__main__':
n, m = [int(s) for s in input().split()]
E = [set() for _ in range(n)]
for _ in range(m):
s, t = [int(s) for s in input().split(" ")]
E[s].add(t)
E[t].add(s)
def dfs(current, prev):
global timer
prenum[current... |
s303842990 | p02367 | u967553879 | 1556843407 | Python | Python3 | py | Runtime Error | 0 | 0 | 1310 | from collections import deque
sys.setrecursionlimit(1000000)
def dfs(current, prev):
global time
# node currentを訪問した直後の処理
ord[current] = time
low[current] = time
time += 1
color[current] = BLACK
for next in G[current]:
if color[next] == WHITE:
# node currentからnode next... |
s729066645 | p02367 | u797673668 | 1461576355 | Python | Python3 | py | Runtime Error | 40 | 8992 | 797 | n, m = map(int, input().split())
edges = [set() for _ in range(n)]
for _ in range(m):
s, t = map(int, input().split())
edges[s].add(t)
edges[t].add(s)
prenum = [None] * n
parent = [None] * n
lowest = [None] * n
counter = 0
bridges = set()
def dfs(cur, prev):
global counter
prenum[cur] = lowest[... |
s408332130 | p02367 | u022407960 | 1480484486 | Python | Python3 | py | Runtime Error | 30 | 8956 | 2160 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 4
0 1
1 2
2 3
3 4
output:
0 1
1 2
2 3
3 4
"""
import sys
# sys.setrecursionlimit(int(3e6))
def generate_adj_table(_v_info):
for v_detail in _v_info:
v_from, v_to = map(int, v_detail)
init_adj_table[v_from].append(v_to)
# undirec... |
s878913971 | p02367 | u022407960 | 1480484549 | Python | Python3 | py | Runtime Error | 0 | 0 | 2159 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 4
0 1
1 2
2 3
3 4
output:
0 1
1 2
2 3
3 4
"""
import sys
sys.setrecursionlimit(int(1e10))
def generate_adj_table(_v_info):
for v_detail in _v_info:
v_from, v_to = map(int, v_detail)
init_adj_table[v_from].append(v_to)
# undirect... |
s427778962 | p02367 | u798803522 | 1508077762 | Python | Python3 | py | Runtime Error | 0 | 0 | 1232 | from collections import defaultdict
import sys
sys.setrecursionlimit(100000)
def seq():
a = 1
while True:
yield a
a += 1
def dfs(here, went, connect, discovery, low, answer, seq):
went |= {here}
discovery[here] = low[here] = next(seq)
child = 0
for con in connect[here]:
... |
s986602917 | p02367 | u798803522 | 1508077844 | Python | Python3 | py | Runtime Error | 0 | 0 | 1232 | from collections import defaultdict
import sys
sys.setrecursionlimit(100000)
def seq():
a = 1
while True:
yield a
a += 1
def dfs(here, went, connect, discovery, low, answer, seq):
went |= {here}
discovery[here] = low[here] = next(seq)
child = 0
for con in connect[here]:
... |
s204853134 | p02368 | u567380442 | 1428195864 | Python | Python3 | py | Runtime Error | 0 | 0 | 1664 | def search(g, v):
visited = set()
lowest = [None] * v
parent = [None] * v
prenum = [None] * v
child = defaultdict(list)
root = 0
# dfs??§tree?????????
stack = [(root, None)]
while stack:
u, prev = stack.pop()
if u not in visited:
parent[u] = prev
... |
s157612326 | p02368 | u567380442 | 1428195926 | Python | Python3 | py | Runtime Error | 30 | 6800 | 1700 | def search(g, v):
visited = set()
lowest = [None] * v
parent = [None] * v
prenum = [None] * v
child = defaultdict(list)
root = 0
# dfs??§tree?????????
stack = [(root, None)]
while stack:
u, prev = stack.pop()
if u not in visited:
parent[u] = prev
... |
s117398597 | p02368 | u567380442 | 1428207239 | Python | Python3 | py | Runtime Error | 0 | 0 | 1762 | from collections import defaultdict
from collections import Counter
def search(g, v):
visited = set()
lowest = [None] * v
parent = [None] * v
prenum = [None] * v
child = defaultdict(list)
backtrack = defaultdict(set)
for root in range(v):
if root in visited:
continue
... |
s111787803 | p02368 | u797673668 | 1461579413 | Python | Python3 | py | Runtime Error | 140 | 8436 | 1019 | def f_dfs(i):
global f_edges, counter
visited[i] = True
for edge in f_edges[i]:
if visited[edge]:
continue
f_dfs(edge)
finish_order[i] = (counter, i)
counter += 1
def b_dfs(i, group):
global b_edges, groups
visited[i] = True
groups[i] = group
for edge in... |
s184108483 | p02368 | u022407960 | 1480492151 | Python | Python3 | py | Runtime Error | 90 | 9844 | 2759 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 6
0 1
1 0
1 2
2 4
4 3
3 2
4
0 1
0 3
2 3
3 4
output:
1
0
1
1
"""
import sys
sys.setrecursionlimit(int(1e4))
def generate_adj_table(_v_info):
for v_detail in _v_info:
v_from, v_to = map(int, v_detail)
init_adj_table[v_from].append(v_to)
... |
s800372080 | p02368 | u022407960 | 1480527058 | Python | Python3 | py | Runtime Error | 210 | 67532 | 2395 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
5 6
0 1
1 0
1 2
2 4
4 3
3 2
4
0 1
0 3
2 3
3 4
output:
1
0
1
1
"""
import sys
from math import isinf
sys.setrecursionlimit(int(1e6))
def generate_adj_table(_v_info):
for v_detail in _v_info:
v_from, v_to = map(int, v_detail)
init_adj_tabl... |
s608785094 | p02368 | u894114233 | 1482652349 | Python | Python | py | Runtime Error | 40 | 6508 | 991 | def add_edge(frm,to):
g[frm].append(to)
rg[to].append(frm)
def dfs(now,used,back_track):
used[now]=True
for nx in g[now]:
if not used[nx]:dfs(nx,used,back_track)
back_track.append(now)
def rdfs(now,num_cmp,used,cmp):
used[now]=True
cmp[now]=num_cmp
for nx in rg[now]:
if... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.