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
s705330673
p02368
u400336986
1487593289
Python
Python3
py
Runtime Error
280
8016
801
def dfs(u, g, stack): visited[u] = True for v in g[u]: if not visited[v]: dfs(v, g, stack) stack.append(u) return stack nv, ne = map(int, input().split(' ')) adj, tps = ([[] for _ in range(nv)] for _ in range(2)) for _ in range(ne): s, t = map(int, input().split(' ')) adj[s...
s966539963
p02368
u855775311
1499781277
Python
Python3
py
Runtime Error
140
8264
1032
def main(): nvertices, nedges = map(int, input().split()) Adj = [[] for i in range(nvertices)] Adjrev = [[] for i in range(nvertices)] for i in range(nedges): s, t = map(int, input().split()) Adj[s].append(t) Adjrev[t].append(s) component_ids = [-1] * nvertices id = 0 ...
s169080503
p02368
u855775311
1499920890
Python
Python3
py
Runtime Error
0
0
1241
def main(): nvertices, nedges = map(int, input().split()) Adj = [[] for i in range(nvertices)] Adjrev = [[] for i in range(nvertices)] for i in range(nedges): s, t = map(int, input().split()) Adj[s].append(t) Adjrev[t].append(s) ordering = [] visited = [False] * nvertice...
s325399044
p02368
u855775311
1499920982
Python
Python3
py
Runtime Error
130
8176
1249
def main(): nvertices, nedges = map(int, input().split()) Adj = [[] for i in range(nvertices)] Adjrev = [[] for i in range(nvertices)] for i in range(nedges): s, t = map(int, input().split()) Adj[s].append(t) Adjrev[t].append(s) ordering = [] visited = [False] * nvertice...
s526226443
p02368
u855775311
1499921156
Python
Python3
py
Runtime Error
120
8024
1299
import sys def main(): sys.setrecursionlimit(int(1e4)) nvertices, nedges = map(int, input().split()) Adj = [[] for i in range(nvertices)] Adjrev = [[] for i in range(nvertices)] for i in range(nedges): s, t = map(int, input().split()) Adj[s].append(t) Adjrev[t].append(s) ...
s106263419
p02368
u855775311
1501749583
Python
Python3
py
Runtime Error
110
7924
1114
def main(): nvertices, nedges = map(int, input().split()) Adj = [[] for i in range(nvertices)] AdjRev = [[] for i in range(nvertices)] for i in range(nedges): u, v = map(int, input().split()) Adj[u].append(v) AdjRev[v].append(u) lst = [] visited = [False] * nvertices ...
s419177994
p02368
u798803522
1508158537
Python
Python3
py
Runtime Error
150
8544
1430
from collections import defaultdict def counter(): cnt = 0 while True: yield cnt cnt += 1 def dfs(here, visited, track, count, connect): visited |= {here} for c in connect[here]: if c not in visited: dfs(c, visited, track, count, connect) track[here] = next(coun...
s159978713
p02368
u798803522
1508158584
Python
Python3
py
Runtime Error
0
0
1460
from collections import defaultdict sys.setrecursionlimit(100000) def counter(): cnt = 0 while True: yield cnt cnt += 1 def dfs(here, visited, track, count, connect): visited |= {here} for c in connect[here]: if c not in visited: dfs(c, visited, track, count, connec...
s447351435
p02368
u352394527
1528130011
Python
Python3
py
Runtime Error
200
6056
1222
""" 強連結成分分解 """ def dfs(v, visited, edges, order): visited[v] = True for to in edges[v]: if not visited[to]: dfs(to, visited, edges, order) order.append(v) def search_strongly_connection(v, visited, reverse_edges, parent): visited[v] = True for to in reverse_edges[v]: if not visited[to]: ...
s577430336
p02369
u797673668
1461582089
Python
Python3
py
Runtime Error
20
7712
779
import sys sys.setrecursionlimit(200000) def dfs(i): global edges, visited, root, duplicated visited[i] = True for edge in edges[i]: if visited[edge]: if edge == root: return True duplicated.add(edge) continue if dfs(edge): r...
s710746056
p02369
u603049633
1497844394
Python
Python3
py
Runtime Error
30
7792
722
import heapq as pq inf = float("inf") n,e = map(int, input().split()) M = [[] for i in range(n)] L = list(map(int, range(n))) for i in range(e): s,t = map(int, input().split()) M[s].append(t) if t in L: L.remove(t) def dijkstra(s): color = [0] * n H =[] pq.heappush(H, s) whil...
s874350260
p02369
u893844544
1523855949
Python
Python3
py
Runtime Error
0
0
426
nv,ne = [int(i) for i in input().split()] a = [] for i in range(nv): a.append([]) for i in range(ne): s,t = [int(j) for j in input().split()] a[s].append(t) done = [] flag = 0 def put_forword(index): global f if index in done: return done.append(index) for s in a[index]: ...
s588145984
p02369
u893844544
1523858360
Python
Python3
py
Runtime Error
0
0
429
nv,ne = [int(i) for i in input().split()] g = [[] for i in range(nv)] for i in range(ne): s,t = [int(j) for j in input().split()] g[s].append(t) done = [] f = 0 def put_forword(index): global f if index in done: return done.append(index) for i in g[index]: if i == 0 and ...
s531085172
p02370
u011621222
1540444477
Python
Python3
py
Runtime Error
20
5664
442
# -*- coding: utf-8 -*- # 文字列の入力 import math V,E = map(int ,input().split()) X = [] for i in range(E): s_i, t_i = map(int , input().split()) if(s_i in X): if(t_i in X): t = X.index(t_i) s = X.index(s_i) if(s > t): X.remove(t_i) X.insert(s,t_i) else: X.append(t_i) else: if(t_i in X): t...
s189501960
p02370
u967553879
1556259677
Python
Python3
py
Runtime Error
0
0
1009
def topologicalSortBfs(n): for i in range(n): color[i] = WHITE for i in range(0, n): if indeg[i] == 0 and color[i] == WHITE: bfs(i) def bfs(s): Q.appendleft(s) color[s] = GRAY while Q: u = Q.popleft() out.append(u) for v in G[u]: i...
s311039860
p02370
u099826363
1556717798
Python
Python3
py
Runtime Error
40
6840
701
from sys import exit import queue V,E = [int(n) for n in input().split()] ans = [] # N = int(input()) graph = [[] for _ in range(V)] indeg = [0]*E yet = [True]*E def bfs(s): q = queue.Queue() q.put(s) while(not q.empty()): u = q.get() ans.append(u) yet[u]=False for v in grap...
s327024893
p02370
u099826363
1556717874
Python
Python3
py
Runtime Error
40
6840
701
from sys import exit import queue V,E = [int(n) for n in input().split()] ans = [] # N = int(input()) graph = [[] for _ in range(E)] indeg = [0]*E yet = [True]*E def bfs(s): q = queue.Queue() q.put(s) while(not q.empty()): u = q.get() ans.append(u) yet[u]=False for v in grap...
s959517610
p02370
u067972379
1559212067
Python
Python3
py
Runtime Error
0
0
1069
from collections import deque, defaultdict def topological_sort(V, E): ''' Kahn's Algorithm (O(|V| + |E|) time) Input: V = [0, 1, ..., N-1]: a list of vertices of the digraph E: the adjacency list of the digraph (dict) Output: If the input digraph is acyclic, then return a topological sorti...
s900224205
p02370
u894114233
1461422655
Python
Python
py
Runtime Error
10
6800
697
from collections import deque def Topologicalsort(): for i in xrange(v): if indeg[i]==0 and color[i]==0: bfs(i) def bfs(s): color[s]=2 q.append(s) while len(q)>0: i=q.popleft() ans.append(i) for j in xrange(v): if m[i][j]!=-1 and color[j]==0 : ...
s080724592
p02370
u894114233
1461422906
Python
Python
py
Runtime Error
10
6800
688
from collections import deque def Topologicalsort(): for i in xrange(v): if indeg[i]==0 and color[i]==0: bfs(i) def bfs(s): color[s]=2 q.append(s) while len(q)>0: i=q.popleft() ans.append(i) for j in xrange(v): if m[i][j]!=-1: ind...
s164985054
p02370
u462831976
1490603572
Python
Python3
py
Runtime Error
40
8676
830
# -*- coding: utf-8 -*- import sys import os import pprint from queue import Queue """Topological Sort""" #fd = os.open('GRL_4_B.txt', os.O_RDONLY) #os.dup2(fd, sys.stdin.fileno()) V, E = list(map(int, input().split())) G = [[] for i in range(V)] indig = [0] * V # ??\?¬???° for i in range(V): s, t = list(map(in...
s492553537
p02370
u426534722
1500821701
Python
Python3
py
Runtime Error
0
0
469
from sys import stdin from collections import deque V, E = map(int, stdin.readline().split()) adj_list = [[] for _ in [] * V] is_visited = [False] * V for _ in [] * E: s, t = map(int, stdin.readline().split()) adj_list[s].append(t) out = deque() def dfs(u): is_visited[u] = True for v in adj_list[u]: ...
s162708980
p02370
u426534722
1500821728
Python
Python3
py
Runtime Error
0
0
470
from sys import stdin from collections import deque V, E = map(int, stdin.readline().split()) adj_list = [[] for _ in [] * V] is_visited = [False] * V for _ in [0] * E: s, t = map(int, stdin.readline().split()) adj_list[s].append(t) out = deque() def dfs(u): is_visited[u] = True for v in adj_list[u]: ...
s907833658
p02370
u792145349
1528975773
Python
Python3
py
Runtime Error
0
0
516
N, M = map(int, input().split()) G = [[] for i in range(N)] for i in range(M): s, t = map(int, input().split()) G[s].append(t) def topological_sort(g): topological_list = [] visited = set() def dfs(n): for e in g[n]: if e not in visited: dfs(e) topologic...
s257941396
p02371
u138546245
1534991840
Python
Python3
py
Runtime Error
20
6248
1710
#!/usr/bin/env python3 # GRL_5_A: Tree - Diameter of a Tree class Edge: __slots__ = ('v', 'w') def __init__(self, v, w): self.v = v self.w = w def either(self): return self.v def other(self, v): if v == self.v: return self.w else: retu...
s723042716
p02371
u943441430
1559280055
Python
Python3
py
Runtime Error
20
5668
934
from heapq import heappush, heappop INF = 10000000000 def dijkstra(r, v, dic): dp = [] q = [] dp = [INF] * v dp[r] = 0 heappush(q, (0, r)) while q: cost, vtx = heappop(q) if dp[vtx] < cost: continue for vtx1, cost1 in dic[vtx]: if cost + cost1 <...
s636298060
p02371
u943441430
1559280089
Python
Python3
py
Runtime Error
20
5664
924
from heapq import heappush, heappop INF = 10000000000 def dijkstra(r, v, dic): dp = [] q = [] dp = [INF] * v dp[r] = 0 heappush(q, (0, r)) while q: cost, vtx = heappop(q) if dp[vtx] < cost: continue for vtx1, cost1 in dic[vtx]: if cost + cost1 <...
s900104419
p02371
u943441430
1559282570
Python
Python3
py
Runtime Error
20
6220
665
def solve(prev, r, dic): d = 0 t = r if r in dic: for vtx, cost in dic[r]: if vtx == prev: continue d1, t1 = solve(r, vtx, dic) d1 += cost if d < d1: d = d1 t = t1 return d, t line = input() n = int(...
s896418709
p02371
u943441430
1559282654
Python
Python3
py
Runtime Error
20
6220
665
def solve(prev, r, dic): d = 0 t = r if r in dic: for vtx, cost in dic[r]: if vtx == prev: continue d1, t1 = solve(r, vtx, dic) d1 += cost if d < d1: d = d1 t = t1 return d, t line = input() n = int(...
s015717608
p02371
u943441430
1559285284
Python
Python3
py
Runtime Error
290
16788
707
import sys sys.setrecursionlimit(10000) def solve(prev, r, dic): d = 0 t = r if r in dic: for vtx, cost in dic[r]: if vtx == prev: continue d1, t1 = solve(r, vtx, dic) d1 += cost if d < d1: d = d1 t = t...
s948763989
p02371
u943441430
1559285310
Python
Python3
py
Runtime Error
820
43928
707
import sys sys.setrecursionlimit(50000) def solve(prev, r, dic): d = 0 t = r if r in dic: for vtx, cost in dic[r]: if vtx == prev: continue d1, t1 = solve(r, vtx, dic) d1 += cost if d < d1: d = d1 t = t...
s205742847
p02371
u943441430
1559285339
Python
Python3
py
Runtime Error
750
43924
708
import sys sys.setrecursionlimit(100000) def solve(prev, r, dic): d = 0 t = r if r in dic: for vtx, cost in dic[r]: if vtx == prev: continue d1, t1 = solve(r, vtx, dic) d1 += cost if d < d1: d = d1 t = ...
s751108930
p02371
u567380442
1428235656
Python
Python3
py
Runtime Error
40
6756
847
def postorder(g): parent_stack = [None] dfs_stack = [(0, None)] while dfs_stack: u, prev = dfs_stack.pop() dfs_stack.extend((t, u) for d, t in g[u]) while parent_stack[-1] != prev: yield parent_stack.pop() parent_stack.append(u) while parent_stack[...
s832427108
p02371
u567380442
1428236297
Python
Python3
py
Runtime Error
30
6764
945
def root(g): return set(g.keys()).difference({y for x in g.values() for y in x}).pop() def postorder(g): parent_stack = [None] dfs_stack = [(root(g), None)] while dfs_stack: u, prev = dfs_stack.pop() dfs_stack.extend((t, u) for d, t in g[u]) while parent_stack[-1] !=...
s849577171
p02371
u072053884
1477707059
Python
Python3
py
Runtime Error
230
15936
553
# Acceptance of input import sys f_i = sys.stdin n = int(f_i.readline()) edges = [[None] * n for i in range(n)] for l_i in f_i: s, t, w = map(int, l_i.split()) edges[s][t] = w edges[t][s] = w # Tree Walk and Output distance = [0] * n def tree_walk(u, d, p): for v, e in enumerate(edges[u]): ...
s793960812
p02371
u072053884
1477759074
Python
Python3
py
Runtime Error
30
8028
1470
# Acceptance of input import sys f_i = sys.stdin n = int(f_i.readline()) edges = [[None] * n for i in range(n)] for l_i in f_i: s, t, w = map(int, l_i.split()) edges[s][t] = w edges[t][s] = w # dfs tree walk 1 import collections path = collections.deque() path.append(0) distance = 0 max_distance = ...
s307578639
p02371
u072053884
1477830715
Python
Python3
py
Runtime Error
150
20612
566
# Acceptance of input import sys f_i = sys.stdin n = int(f_i.readline()) edges = [[] for i in range(n)] for l_i in f_i: s, t, w = map(int, l_i.split()) edges[s].append([t, w]) edges[t].append([s, w]) # Tree Walk and Output distance = [0] * n sys.setrecursionlimit(10000) def tree_walk(u, d, p): ...
s361206091
p02371
u072053884
1477830786
Python
Python3
py
Runtime Error
500
94944
567
# Acceptance of input import sys f_i = sys.stdin n = int(f_i.readline()) edges = [[] for i in range(n)] for l_i in f_i: s, t, w = map(int, l_i.split()) edges[s].append([t, w]) edges[t].append([s, w]) # Tree Walk and Output distance = [0] * n sys.setrecursionlimit(100000) def tree_walk(u, d, p): ...
s378573805
p02371
u072053884
1477830822
Python
Python3
py
Runtime Error
510
94916
567
# Acceptance of input import sys f_i = sys.stdin n = int(f_i.readline()) edges = [[] for i in range(n)] for l_i in f_i: s, t, w = map(int, l_i.split()) edges[s].append([t, w]) edges[t].append([s, w]) # Tree Walk and Output distance = [0] * n sys.setrecursionlimit(200000) def tree_walk(u, d, p): ...
s725953730
p02371
u260980560
1500111153
Python
Python
py
Runtime Error
0
0
591
while 1: n = input() if n == 0: break G = [[] for i in xrange(n)] for i in xrange(n-1): s, t, w = map(int, raw_input().split()) G[s].append((t, w)) G[t].append((s, w)) def dfs(s, prev): if prev != -1 and len(G[s]) == 1: return (0, s) res =...
s830985785
p02371
u260980560
1500111176
Python
Python
py
Runtime Error
0
0
631
import sys sys.setrecursionlimit(10**6) while 1: n = input() if n == 0: break G = [[] for i in xrange(n)] for i in xrange(n-1): s, t, w = map(int, raw_input().split()) G[s].append((t, w)) G[t].append((s, w)) def dfs(s, prev): if prev != -1 and len(G[s]) == 1:...
s285166837
p02371
u260980560
1500111221
Python
Python
py
Runtime Error
470
91060
509
import sys sys.setrecursionlimit(10**6) n = input() G = [[] for i in xrange(n)] for i in xrange(n-1): s, t, w = map(int, raw_input().split()) G[s].append((t, w)) G[t].append((s, w)) def dfs(s, prev): if prev != -1 and len(G[s]) == 1: return (0, s) res = (0, -1) for t, w in G[s]: ...
s656967478
p02371
u260980560
1500111591
Python
Python
py
Runtime Error
490
95028
474
import sys sys.setrecursionlimit(10**6) n = input() G = [[] for i in xrange(n)] for i in xrange(n-1): s, t, w = map(int, raw_input().split()) G[s].append((t, w)) G[t].append((s, w)) def dfs(s, prev): if prev != -1 and len(G[s]) == 1: return (0, s) res = (0, s) for t, w in G[s]: ...
s319285156
p02371
u426534722
1501104919
Python
Python3
py
Runtime Error
0
0
718
import sys readline = sys.stdin.readline from collections import deque from math import isinf INF = float("inf") sys.setrecursionlimit(200000) n = int(readline()) G = [[] for _ in range(n)] for _ in [0] * (n - 1): s, t, w = map(int, readline().split()) G[s].append([t, w]) G[t].append([s, w]) def bfs(s, D): ...
s350380047
p02371
u798803522
1508662368
Python
Python3
py
Runtime Error
60
8412
868
from collections import defaultdict def dfs(source, used, all_weight, connect): max_weight = all_weight max_source = source used[source] = 1 for target, weight in connect[source]: if not used[target]: now_weight = all_weight + weight this_source, this_weight = dfs(target...
s906142384
p02371
u798803522
1508662414
Python
Python3
py
Runtime Error
830
54372
909
from collections import defaultdict import sys sys.setrecursionlimit(100000) def dfs(source, used, all_weight, connect): max_weight = all_weight max_source = source used[source] = 1 for target, weight in connect[source]: if not used[target]: now_weight = all_weight + weight ...
s366159095
p02372
u138546245
1535095693
Python
Python3
py
Runtime Error
20
5684
3004
#!/usr/bin/env python3 # GRL_5_B: Tree - Height of a Tree import bisect class Edge: __slots__ = ('v', 'w') def __init__(self, v, w): self.v = v self.w = w def either(self): return self.v def other(self, v): if v == self.v: return self.w else: ...
s522342851
p02372
u567380442
1428286644
Python
Python3
py
Runtime Error
30
6800
1400
from sys import stdin from collections import defaultdict readline = stdin.readline def main(): n = int(readline()) g = defaultdict(list) for _ in range(n - 1): s, t, d = map(int, readline().split()) g[s].append([d, t]) dp = defaultdict(dict) r = root(g) for i in postorder(g, ...
s750439590
p02372
u797673668
1461663787
Python
Python3
py
Runtime Error
30
7752
1027
import sys from operator import itemgetter sys.setrecursionlimit(200000) def dfs(u, prev): global post_order, pre_order pre_order.append((u, prev)) for w, t in edges[u]: if t != prev: dfs(t, u) post_order.append(u) n = int(input()) edges = [set() for _ in range(n)] for _ in ra...
s899231018
p02372
u798803522
1508670418
Python
Python3
py
Runtime Error
0
0
1041
from collections import defaultdict import sys sys.setrecursionlimit(200000) def dfs(source, edge_index, connect): if connect[source][edge_index][2] >= 0: return connect[source][edge_index][2] this_edge = connect[source][edge_index] this_edge[2] = this_edge[1] dest = this_edge[0] for i, (ne...
s175574039
p02372
u798803522
1508671622
Python
Python3
py
Runtime Error
0
0
1321
from collections import defaultdict import sys sys.setrecursionlimit(200000) def dfs(source, edge_index, connect, used): if used[source] or connect[source][edge_index][2] >= 0: return connect[source][edge_index][2] used[source] = 1 this_edge = connect[source][edge_index] this_edge[2] = this_edg...
s403533908
p02372
u798803522
1508675521
Python
Python3
py
Runtime Error
0
0
1645
# for undirected graph from collections import defaultdict import sys sys.setrecursionlimit(200000) def dfs(source, edge_index, connect, used): if connect[source][edge_index][3] or connect[source][edge_index][2] >= 0: return connect[source][edge_index][2] connect[source][edge_index][3] = 1 this_ed...
s076566577
p02372
u798803522
1508681398
Python
Python3
py
Runtime Error
0
0
1721
# for undirected graph from collections import defaultdict import sys sys.setrecursionlimit(200000) def dfs(source, edge_index, connect): if connect[source][edge_index][3] or connect[source][edge_index][2] >= 0: return connect[source][edge_index][2] connect[source][edge_index][3] = 1 this_edge = c...
s050646246
p02372
u798803522
1508681433
Python
Python3
py
Runtime Error
0
0
1687
# for undirected graph from collections import defaultdict import sys sys.setrecursionlimit(200000) def dfs(source, edge_index, connect): if connect[source][edge_index][3] or connect[source][edge_index][2] >= 0: return connect[source][edge_index][2] connect[source][edge_index][3] = 1 this_edge = c...
s656616893
p02373
u082657995
1556376524
Python
Python3
py
Runtime Error
20
5624
1752
class Lca: def __init__(self, E, root): import sys sys.setrecursionlimit(500000) self.root = root self.E = E # V<V> self.n = len(E) # 頂点数 self.logn = 0 while self.n > (1<<self.logn): self.logn += 1 # parent[n][v] = ノード v から 1<<n 個親をたどったノ...
s977228897
p02373
u894114233
1471704708
Python
Python
py
Runtime Error
480
19080
1345
# -*- coding: utf-8 -*- from math import log def dfs(v,p,d): parent[0][v]=p depth[v]=d for i in xrange(len(G[v])): if G[v][i]!=p: dfs(G[v][i],v,d+1) def init(vn,root): dfs(root,-1,0) k=0 while k+1<log(vn,2): for v in xrange(vn): if parent[k][v]<0: ...
s649570266
p02373
u894114233
1471704919
Python
Python
py
Runtime Error
1080
82012
1385
# -*- coding: utf-8 -*- from math import log import sys sys.setrecursionlimit(10**7) def dfs(v,p,d): parent[0][v]=p depth[v]=d for i in xrange(len(G[v])): if G[v][i]!=p: dfs(G[v][i],v,d+1) def init(vn,root): dfs(root,-1,0) k=0 while k+1<log(vn,2): for v in xrange(vn...
s423519560
p02373
u894114233
1471704965
Python
Python
py
Runtime Error
1100
81980
1385
# -*- coding: utf-8 -*- from math import log import sys sys.setrecursionlimit(10**9) def dfs(v,p,d): parent[0][v]=p depth[v]=d for i in xrange(len(G[v])): if G[v][i]!=p: dfs(G[v][i],v,d+1) def init(vn,root): dfs(root,-1,0) k=0 while k+1<log(vn,2): for v in xrange(vn...
s241355782
p02373
u022407960
1481776093
Python
Python3
py
Runtime Error
30
7968
1801
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 16 3 1 2 3 3 4 5 6 0 2 7 8 0 2 9 10 2 14 15 0 0 0 3 11 12 13 0 0 0 0 0 10 1 3 4 5 4 9 4 10 4 13 9 13 9 14 9 8 13 14 13 7 output: 0 1 1 1 1 5 1 0 1 0 """ import sys import math def dfs(v, v_parent, v_depth): parent[0][v] = v_parent depth[v] = v_depth...
s474160311
p02373
u022407960
1481776135
Python
Python3
py
Runtime Error
20
7904
1834
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 16 3 1 2 3 3 4 5 6 0 2 7 8 0 2 9 10 2 14 15 0 0 0 3 11 12 13 0 0 0 0 0 10 1 3 4 5 4 9 4 10 4 13 9 13 9 14 9 8 13 14 13 7 output: 0 1 1 1 1 5 1 0 1 0 """ import sys import math sys.setrecursionlimit(int(1e5)) def dfs(v, v_parent, v_depth): parent[0][v] ...
s869009376
p02373
u022407960
1481806461
Python
Python3
py
Runtime Error
30
7960
1939
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 16 3 1 2 3 3 4 5 6 0 2 7 8 0 2 9 10 2 14 15 0 0 0 3 11 12 13 0 0 0 0 0 10 1 3 4 5 4 9 4 10 4 13 9 13 9 14 9 8 13 14 13 7 output: 0 1 1 1 1 5 1 0 1 0 """ import sys import math sys.setrecursionlimit(int(1e5)) def dfs(v, v_parent, v_depth): # print(paren...
s560784192
p02373
u022407960
1481806815
Python
Python3
py
Runtime Error
860
105140
1939
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 16 3 1 2 3 3 4 5 6 0 2 7 8 0 2 9 10 2 14 15 0 0 0 3 11 12 13 0 0 0 0 0 10 1 3 4 5 4 9 4 10 4 13 9 13 9 14 9 8 13 14 13 7 output: 0 1 1 1 1 5 1 0 1 0 """ import sys import math sys.setrecursionlimit(int(1e5)) def dfs(v, v_parent, v_depth): # print(paren...
s989481025
p02373
u022407960
1481971667
Python
Python3
py
Runtime Error
0
0
1685
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 3 0.0 0.0 2.0 0.0 1.0 1.0 output: 1.41421356237 """ import sys from operator import attrgetter class ClosestPair(object): def __init__(self, in_data): """ Init closest pairs points set. """ self.p_num = int(in_data[0]) ...
s095425140
p02373
u022407960
1481971749
Python
Python3
py
Runtime Error
0
0
1697
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 3 0.0 0.0 2.0 0.0 1.0 1.0 output: 1.41421356237 """ import sys from operator import attrgetter class ClosestPair(object): def __init__(self, in_data): """ Init closest pairs points set. """ self.p_num = int(in_data[0]) ...
s530115706
p02373
u408260374
1482328592
Python
Python3
py
Runtime Error
640
35864
2003
class Edge: def __init__(self, dst, weight): self.dst, self.weight = dst, weight def __lt__(self, e): return self.weight > e.weight class Graph: def __init__(self, V): self.V = V self.E = [[] for _ in range(V)] def add_edge(self, src, dst, weight): self.E[src]...
s665391174
p02373
u408260374
1482328676
Python
Python3
py
Runtime Error
980
95504
2045
import sys sys.setrecursionlimit(10**6) class Edge: def __init__(self, dst, weight): self.dst, self.weight = dst, weight def __lt__(self, e): return self.weight > e.weight class Graph: def __init__(self, V): self.V = V self.E = [[] for _ in range(V)] def add_edge(se...
s810976017
p02373
u797673668
1488274450
Python
Python3
py
Runtime Error
450
27696
1025
from math import log2 def build(): dfs(tree, 0, -1, 0) pk0 = parent[0] for k in range(1, logn): pk1 = parent[k] for v in range(n): pkv = pk0[v] pk1[v] = -1 if pkv < 0 else pk0[pkv] pk0 = pk1 def dfs(tree, v, p, d): parent[0][v] = p depth[v] = d ...
s841520214
p02373
u797673668
1488274533
Python
Python3
py
Runtime Error
1340
96168
1068
import sys sys.setrecursionlimit(100000) from math import log2 def build(): dfs(tree, 0, -1, 0) pk0 = parent[0] for k in range(1, logn): pk1 = parent[k] for v in range(n): pkv = pk0[v] pk1[v] = -1 if pkv < 0 else pk0[pkv] pk0 = pk1 def dfs(tree, v, p, d)...
s972907851
p02373
u260980560
1500114790
Python
Python
py
Runtime Error
20
6688
1079
from collections import deque n = input() C = [None]*n P = [None]*n for i in xrange(n): ipt = map(int, raw_input().split()) C[i] = ipt[1:] for c in C[i]: P[c] = i LEV = (n+1).bit_length() parent = [[None]*(LEV + 1) for i in xrange(n)] for i in xrange(n): parent[i][0] = P[i] for k in xrange(1, L...
s551298889
p02373
u798803522
1508767122
Python
Python3
py
Runtime Error
70
8152
1225
import math from collections import defaultdict def dfs(here, p, d, parent, depth, connect): parent[0][here] = p depth[here] = d for next_v in connect[here]: dfs(next_v, here, d + 1, parent, depth, connect) def lca(v1, v2, parent, depth): if depth[v2] > depth[v1]: v1, v2 = v2, v1 f...
s807828051
p02373
u798803522
1508767226
Python
Python3
py
Runtime Error
720
24764
1233
import math from collections import defaultdict def dfs(here, p, d, parent, depth, connect): parent[0][here] = p depth[here] = d for next_v in connect[here]: dfs(next_v, here, d + 1, parent, depth, connect) def lca(v1, v2, parent, depth): if depth[v2] > depth[v1]: v1, v2 = v2, v1 f...
s496228135
p02374
u847485844
1559098521
Python
Python
py
Runtime Error
0
0
3808
N = 10 ** 5 prt = [0] * (N + 1) left = [-1] + [0] * N right = [-1] + [0] * N sz = [0] + [1] * N key = [0] * (N + 1) val = [0] * (N + 1) rev = [0] * (N + 1) def update(i, l, r): # assert 1 <= i <= N sz[i] = 1 + sz[l] + sz[r] val[i] = key[i] + val[l] + val[r] def swap(i): if i: left[i], right[...
s187726677
p02374
u210794057
1559302739
Python
Python
py
Runtime Error
0
0
1132
import sys   sys.setrecursionlimit(int(1e6))     class BIT:     def __init__(self, n):         self.n = n         self.data = [0] * (n + 1)       def get_sum(self, i):         ret = 0         while i > 0:             ret += self.data[i]             i -= (i & -i)         return ret       def add(self, i, w):         if ...
s013981205
p02374
u210794057
1559302763
Python
Python3
py
Runtime Error
0
0
1132
import sys   sys.setrecursionlimit(int(1e6))     class BIT:     def __init__(self, n):         self.n = n         self.data = [0] * (n + 1)       def get_sum(self, i):         ret = 0         while i > 0:             ret += self.data[i]             i -= (i & -i)         return ret       def add(self, i, w):         if ...
s325049396
p02374
u210794057
1559302929
Python
Python
py
Runtime Error
0
0
765
import sys sys.setrecursionlimit(int(1e6)) class BIT: def __init__(self, n): self.n = n self.data = [0] * (n + 1) def get_sum(self, i): ret = 0 while i > 0: ret += self.data[i] i -= (i & -i) return ret def add(self, i, w): if i == 0: return while i <= self.n: self.data[i] += w i += ...
s859652526
p02374
u686180487
1559377937
Python
Python3
py
Runtime Error
0
0
843
# -*- coding: utf-8 -*- N = int(input()) G = [None for i in range(N)] for i in range(N): temp = list(map(int, input().split())) G[i] = temp[1:] INF = 2**31 -1 temp = 1 while temp < N: temp *= 2 lis = [INF for i in range(2*temp-1)] def getSum(x): x += temp-1 w_sum = lis[x] while x > 0: x = (x-1) //...
s216836427
p02374
u686180487
1559378172
Python
Python3
py
Runtime Error
0
0
900
# -*- coding: utf-8 -*- N = int(input()) G = [None for i in range(N)] for i in range(N): temp = list(map(int, input().split())) G[i] = temp[1:] INF = 2**31 -1 temp = 1 while temp < N: temp *= 2 lis = [INF for i in range(2*temp-1)] def getSum(x): x += temp-1 w_sum = lis[x] while x > 0: x = (x-1) //...
s254865021
p02374
u686180487
1559482826
Python
Python3
py
Runtime Error
130
6344
1026
# -*- coding: utf-8 -*- class weightRtree: def __init__(self, num): self.num = num self.weight = [0] * (num+1) def add(self, v, w): if v == 0: return 0 while v <= self.num: self.weight[v] += w v += (-v) & v def getSum(self, u):...
s682078303
p02376
u138546245
1535991164
Python
Python3
py
Runtime Error
20
5716
2157
from heapq import heappush, heappop class Edge: __slots__ = ('src', 'dest', 'capacity', 'flow') def __init__(self, v, w, capacity): self.src = v self.dest = w self.capacity = capacity self.flow = 0 def other(self, v): if v == self.src: return self.dest...
s388674928
p02376
u419946054
1559523041
Python
Python3
py
Runtime Error
0
0
2046
V, E = map(int, input().split()) # -*- coding: utf-8 -*- import collections import queue class Dinic(): def __init__(self, N): self.N = N self.edges = collections.defaultdict(list) self.level = [0] * N self.iter = [0] * N def add(self, u, v, c, directed=True): """ ...
s029485610
p02376
u647766105
1430392043
Python
Python
py
Runtime Error
0
0
1690
#test def ford_fulkerson(graph, source, sink): N = len(graph) def dfs(cur_node, visited): if cur_node == source: flag = True while flag: flag = False for next_node in xrange(N): if graph[cur_node][next_node] <= 0: ...
s245353289
p02376
u766807750
1432297930
Python
Python3
py
Runtime Error
0
0
1382
def read_data(): nV, nE = map(int, input().split()) cf = [dict() for v in range(nV)] for e in range(nE): u, v, c = map(int, input().split()) if u == t or v == s: continue C[u][v] = c C[v][u] = 0 return C, nV, 0, nV - 1 def dinic(cf, nV, s, t): dist = get_...
s413670266
p02376
u766807750
1432298046
Python
Python3
py
Runtime Error
0
0
1381
def read_data(): nV, nE = map(int, input().split()) C = [dict() for v in range(nV)] for e in range(nE): u, v, c = map(int, input().split()) if u == t or v == s: continue C[u][v] = c C[v][u] = 0 return C, nV, 0, nV - 1 def dinic(cf, nV, s, t): dist = get_d...
s306761428
p02376
u408260374
1433586979
Python
Python3
py
Runtime Error
40
6772
1623
class FordFulkerson: """Ford-Fulkerson Algorithm: find max-flow complexity: O(FE) (F: max flow) """ def __init__(self, V, E, source, sink): """ V: the number of vertexes E: adjacency list source: start point sink: goal point """ self.V = V ...
s951337363
p02376
u408260374
1433587196
Python
Python3
py
Runtime Error
30
6784
1662
import sys sys.setrecursionlimit(3000) class FordFulkerson: """Ford-Fulkerson Algorithm: find max-flow complexity: O(FE) (F: max flow) """ def __init__(self, V, E, source, sink): """ V: the number of vertexes E: adjacency list source: start point sink: goal...
s023075135
p02376
u408260374
1433661442
Python
Python3
py
Runtime Error
0
0
2352
from collections import deque class Dinic: """Dinic Algorithm: find max-flow complexity: O(EV^2) """ class edge: def __init__(self, to, cap, rev): self.to, self.cap, self.rev = to, cap, rev def __init__(self, V, E, source, sink): """ V: the number of vertexes ...
s022150152
p02376
u797673668
1461730468
Python
Python3
py
Runtime Error
60
8776
1225
from queue import deque def hierarchize(source): global edges, hierarchy hierarchy = [-1] * n queue = deque([(0, source)]) while queue: h, v = queue.popleft() if hierarchy[v] != -1: continue hierarchy[v] = h if v == sink: return True queu...
s992039711
p02376
u797673668
1461730505
Python
Python3
py
Runtime Error
40
8752
1267
import sys from queue import deque sys.setrecursionlimit(200000) def hierarchize(source): global edges, hierarchy hierarchy = [-1] * n queue = deque([(0, source)]) while queue: h, v = queue.popleft() if hierarchy[v] != -1: continue hierarchy[v] = h if v == ...
s169232643
p02376
u797673668
1461730565
Python
Python3
py
Runtime Error
40
8824
1267
import sys from queue import deque sys.setrecursionlimit(500000) def hierarchize(source): global edges, hierarchy hierarchy = [-1] * n queue = deque([(0, source)]) while queue: h, v = queue.popleft() if hierarchy[v] != -1: continue hierarchy[v] = h if v == ...
s307968750
p02376
u797673668
1461731046
Python
Python3
py
Runtime Error
20
7840
1266
def hierarchize(source): global edges, hierarchy l, r = 0, 1 hierarchy = [-1] * n hierarchy[source] = 0 queue[0] = source while l != r: v = queue[l] l += 1 if v == sink: break for remain, target, idx in edges[v]: if hierarchy[target] == -1 ...
s412754155
p02376
u766163292
1468497395
Python
Python3
py
Runtime Error
2230
17292
2416
#!/usr/bin/env python3 # Based on https://en.wikipedia.org/wiki/Ford???Fulkerson_algorithm import collections import sys import uuid REC_LIMIT = 10000 class Edge(object): def __init__(self, source, sink, capacity): self.source = source self.sink = sink self.capacity = capacity ...
s182046559
p02376
u022407960
1481010021
Python
Python3
py
Runtime Error
0
0
1933
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 4 5 0 1 2 0 2 1 1 2 1 1 3 1 2 3 2 output: 3 """ import sys from collections import deque def graph_bfs(source, target, parent): visited = [False] * v_num queue = deque() queue.appendleft(source) visited[source] = True while queue: ...
s389260098
p02376
u072053884
1486747675
Python
Python3
py
Runtime Error
30
7916
1643
# Acceptance of input import sys file_input = sys.stdin V, E = map(int, file_input.readline().split()) adj_mat = [[0] * V for i in range(V)] for line in file_input: u, v, c = map(int, line.split()) adj_mat[u][v] = c # Dinic's algorithm import collections # BFS for residual capacity network to construct ...
s462366180
p02376
u072053884
1486780992
Python
Python3
py
Runtime Error
30
7952
1707
# Acceptance of input import sys file_input = sys.stdin V, E = map(int, file_input.readline().split()) adj_mat = [[0] * V for i in range(V)] for line in file_input: u, v, c = map(int, line.split()) adj_mat[u][v] = c # Dinic's algorithm import collections # BFS for residual capacity network to construct ...
s000637086
p02376
u352394527
1528856584
Python
Python3
py
Runtime Error
30
6008
805
from collections import deque INF = 10 ** 20 V, E = map(int, input().split()) net = [[0] * V for _ in range(V)] for _ in range(E): u, v, c = map(int, input().split()) net[u][v] = c start = 0 goal = V - 1 def check_net(node, path, capacity): for i in range(V): cap = net[node][i] if cap != 0: if i...
s728249748
p02377
u797673668
1461749600
Python
Python3
py
Runtime Error
40
7900
1396
from heapq import heappop, heappush def trace(source, edge_trace): v = source for i in edge_trace: e = edges[v][i] yield e v = e[1] def min_cost_flow(source, sink, required_flow): res = 0 while required_flow: visited = set() queue = [(0, source, tuple())] ...
s152935436
p02377
u798803522
1508603195
Python
Python3
py
Runtime Error
0
0
1601
v_num, e_num, flow = (int(n) for n in input().split(" ")) edges = defaultdict(list) for _ in range(e_num): s1, t1, cap, cost = (int(n) for n in input().split(" ")) edges[s1].append([t1, cap, cost, len(edges[t1])]) edges[t1].append([s1, cap, cost, len(edges[s1])]) answer = 0 before_vertice = [float("inf") fo...
s891004489
p02377
u798803522
1508662467
Python
Python3
py
Runtime Error
0
0
909
from collections import defaultdict import sys sys.setrecursionlimit(200000) def dfs(source, used, all_weight, connect): max_weight = all_weight max_source = source used[source] = 1 for target, weight in connect[source]: if not used[target]: now_weight = all_weight + weight ...
s072263069
p02377
u176732165
1523420075
Python
Python
py
Runtime Error
0
0
2851
# -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt import seaborn as sns import pandas as pd import sys import csv import argparse import time import heapq INF = sys.maxint/3 class Edge: def __init__(self, to, cap, cost, rev): self.to = to self.cap = cap self.cost =...
s507700073
p02377
u176732165
1523420102
Python
Python
py
Runtime Error
0
0
2827
import numpy as np import matplotlib.pyplot as plt import seaborn as sns import pandas as pd import sys import csv import argparse import time import heapq INF = sys.maxint/3 class Edge: def __init__(self, to, cap, cost, rev): self.to = to self.cap = cap self.cost = cost self.rev =...