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 int64 0 100 | memory stringlengths 4 6 | code_size int64 15 14.7k | code stringlengths 15 14.7k | problem_id stringlengths 6 6 | problem_description stringlengths 358 9.83k | input stringlengths 2 4.87k | output stringclasses 807
values | __index_level_0__ int64 1.1k 1.22M |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s163977674 | p02238 | u690713461 | 1587268352 | Python | Python3 | py | Accepted | 30 | 6220 | 1,052 | import sys, math
from itertools import permutations, combinations, accumulate
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,182 |
s898803656 | p02238 | u206602962 | 1587234199 | Python | Python3 | py | Accepted | 30 | 6088 | 1,035 | N = int(input())
from collections import deque,defaultdict
G = defaultdict(deque)
for i in range(1,N+1):
t = [int(i) for i in input().split(' ')]
for j in range(t[1]):
G[t[0]].append(t[j+2])
time = 1
arrive_time = [-1] * (N + 1) # 到着時刻
finish_time = [-1] * (N + 1) # 到着時刻
def dfs(G,s):
global time... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,183 |
s848613783 | p02238 | u580036688 | 1587179513 | Python | Python3 | py | Accepted | 20 | 6056 | 659 | from collections import deque
n = int(input())
v = {i:[] for i in range(n)}
for i in range(n):
u = list(map(int, input().split()))
for j in range(2, 2+u[1]):
v[u[0]-1].append(u[j]-1)
global cnt1
cnt1 = 0
visited = [False for _ in range(n)]
f = [0 for _ in range(n)]
l = [0 for _ in range(n)]
def DFS(no... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,184 |
s705985137 | p02238 | u922248744 | 1587147821 | Python | Python3 | py | Accepted | 20 | 5644 | 569 | n = int(input())
vert = [[0,0]+list(map(int,range(1,n+1)))]
parents = [0]
now = 0
time = 0
for i in range(n):
ukv = list(map(int,input().split()))
vert.append([0,0]+ukv[2:])
while(parents):
for i in range(2,len(vert[now])):
if vert[vert[now][i]][0] == 0:
parents.append(now)
n... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,185 |
s111581484 | p02238 | u548252256 | 1587123785 | Python | Python3 | py | Accepted | 20 | 5716 | 680 | def dfs(G,n):
global ptr
#探索済
seen[n] = True
#行き
F[n] = ptr
ptr += 1
for i in G[n]:
#次に行けるかを判定
if seen[i] == True :
continue
dfs(G,i)
#帰り
L[n] = ptr
ptr += 1
if __name__ == '__main__':
n = int(input())
G = [[] for _ in range(n+1)]
F = [0 for _ in range(n+1)]
L = [0 for _ in range(n+1)]... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,186 |
s832863944 | p02238 | u776243834 | 1587109147 | Python | Python3 | py | Accepted | 20 | 5652 | 407 | n = int(input())
u = [list(map(int,input().split())) for _ in range(n)]
ts = [[0,0] for _ in range(n)]
time = 0
def dfs(i):
global time
ts[i][0] = time
for j in range(u[i][1]):
a = u[i][j+2]-1
if ts[a][0] == 0:
time += 1
dfs(a)
time += 1
ts[i][1] = time
for i in range(n):
if ts[i][0]... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,187 |
s762858906 | p02238 | u259225866 | 1587049339 | Python | Python3 | py | Accepted | 30 | 6084 | 1,125 | #深さ優先探索
import sys
input = sys.stdin.readline
from collections import deque
#グラフ作成(無向グラフでは#を消す)
N = int(input())
graph = [deque([]) for _ in range(N+1)]
for _ in range(N):
u, k, *v = [int(x) for x in input().split()]
v.sort()
for i in v:
graph[u].append(i)
#graph[i].append(u)
time ... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,188 |
s019681656 | p02238 | u531262486 | 1586924926 | Python | Python3 | py | Accepted | 20 | 5656 | 708 | import sys
sys.setrecursionlimit(10**6)
n = int(input())
graph = []
chart = [[int(i)] for i in range(1,n+1)]
for i in range(n):
z = [c-1 for c in list(map(int,input().split()))][2:]
graph.append(z)
time = 0
def dfs(nod):
global graph
global time
#break condition
if len(chart[nod]) != 1:
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,189 |
s308035294 | p02238 | u332878765 | 1586887674 | Python | Python3 | py | Accepted | 20 | 5660 | 510 | def dfs(index):
global count
d[index] = count
count += 1
for i in field[index]:
if d[i]:
continue
count = dfs(i)
f[index] = count
return count + 1
n = int(input())
field = [[0,0]]
for _ in range(n):
u, k, *v = map(int, input().split())
field.append(v)
d = [0 ... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,190 |
s630450712 | p02238 | u486404145 | 1586686488 | Python | Python3 | py | Accepted | 20 | 5664 | 804 | # -*- coding: utf-8 -*-
import sys
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()
c=0
def main():
N=int(input())
edge=[[] for _ in range(N)]
for i in range(N):
l=list(map(lambda x:int(x)-1,input().split()))
for x in l[2:]:
edge[i].append(x)
d=[-1]*... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,191 |
s826665596 | p02238 | u043994425 | 1586655144 | Python | Python3 | py | Accepted | 20 | 5716 | 705 | #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B&lang=ja
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
n = INT()
adj = [None]
for _ in range(n):
adj_i = list(map(int, input().split()[2:]))
adj.append(adj_i)
sn... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,192 |
s374132364 | p02238 | u940492895 | 1586616740 | Python | Python3 | py | Accepted | 20 | 5804 | 696 | # 深さ優先探索 Depth first search: DFS
def dfs(u):
global time
color[u - 1] = 0
time += 1
d[u - 1] = time
for v in range(1, n + 1):
if A[u - 1][v - 1] == 1 and color[v - 1] == -1:
dfs(v)
color[u - 1] = 1
time += 1
f[u - 1] = time
n = int(input())
A = [[0 for i in range(... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,193 |
s548202198 | p02238 | u512884261 | 1586534785 | Python | Python3 | py | Accepted | 20 | 5680 | 937 | import sys
input = lambda: sys.stdin.readline().rstrip()
import bisect as bs
def resolve():
n = int(input())
ukv = [list(map(int, input().split())) for _ in range(n)]
d = [-1]*n
f = [-1]*n
stk = []
status = [0]*n
t = 1
for i in range(n):
if status[i]==0:
stk.appen... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,194 |
s704870083 | p02238 | u844375937 | 1586470818 | Python | Python3 | py | Accepted | 50 | 8456 | 8,502 | mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
import time
from bisect import bisect_left, insort_left, bisect_right
import sys
import random
import itertools
input = sys.stdin.readline
_NUMINT_ALL = list(range(10))
_START_TIME = time.time()
INDEX_KETA = 10**12
def main():
ans = s... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,195 |
s780498837 | p02238 | u159581881 | 1586423696 | Python | Python3 | py | Accepted | 20 | 5716 | 530 | n=int(input())
seen=[-1]*n
first_order=[0]*n
last_order=[0]*n
cnt=0
def dfs(G,s):
global cnt
first_order[s]=cnt+1
cnt+=1
seen[s]=1
for nv in G[s]:
if(seen[nv]!=-1):
continue
dfs(G,nv)
last_order[s]=cnt+1
cnt+=1
G=[[] for i in range(n)]
for i in range(n):
li=l... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,196 |
s977397308 | p02238 | u069607647 | 1586413655 | Python | Python3 | py | Accepted | 20 | 5668 | 682 | # coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
def dfs(G, v, d, f, time):
time += 1
d[v] = time
for e in G[v]:
if d[e] == 0:
time = dfs(G, e, d, f, time)
time += 1
f[v] = time
return time
def main():
n = int(readli... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,197 |
s084677137 | p02238 | u115626571 | 1586364335 | Python | Python3 | py | Accepted | 20 | 5636 | 654 | import sys
sys.setrecursionlimit(10**7)
def dfs(G,v):
global ptr
first_order[v] = ptr
ptr += 1
seen[v] = True
for next in G[v]:
if seen[next]:
continue
dfs(G,next)
last_order[v] = ptr
ptr+=1
n = int(input())
G = [[] for _ in range(n)]
for _ in range(n):
a ... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,198 |
s602961351 | p02238 | u013374192 | 1586323199 | Python | Python3 | py | Accepted | 40 | 7104 | 1,378 | import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools
import bisect
# from operator import mul
# sys.setrecursionlimit(100001)
# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)
# ===FUNCTION===
def ge... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,199 |
s175693795 | p02238 | u123563150 | 1586317080 | Python | Python3 | py | Accepted | 20 | 5648 | 488 | n=int(input())
adj=[]
for i in range(n):
a=list(map(int,input().split()))
for j in range(2,len(a)):
a[j]-=1
adj.append(a[2:])
visit_time1=[0]*n
visit_time2=[0]*n
visited=[0]*n
def dfs(now):
global time
visit_time1[now]=time
time+=1
for next in adj[now]:
if not visited[next]:
visited[next]=True
dfs(next... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,200 |
s937053851 | p02238 | u877347085 | 1586187846 | Python | Python3 | py | Accepted | 20 | 6088 | 1,275 | # 深さ優先探索(行きがけ、帰りがけ)
import sys
input = sys.stdin.readline
from collections import deque
# グラフの作成(無向グラフでは#を消す)
N = int(input())
graph = [deque([]) for _ in range(N + 1)]
for _ in range(N):
u, k, * v = [int(x) for x in input().split()] # uは頂点番号、kは隣接頂点の個数
v.sort()
for i in v:
graph[u].append(i)
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,201 |
s327465214 | p02238 | u344362704 | 1586061016 | Python | Python3 | py | Accepted | 20 | 5716 | 547 | n = int(input())
graph = [-1] + [list(map(int, input().split())) for _ in range(n)]
seen = [False]*(n+1)
seen[0] = True
d = [-1]*(n+1)
f = [-1]*(n+1)
time = 0
def dfs(v):
global time
time += 1
d[v] = time
seen[v] = True
k = graph[v][1]
if k > 0:
for i in range(k):
w = graph... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,202 |
s842359284 | p02238 | u820842907 | 1585936541 | Python | Python3 | py | Accepted | 30 | 6040 | 1,181 | from collections import deque
time = 1
def dfs(adj_list, d, f, color, u):
global time
S = list()
S.append(u)
color[u] = "G"
d[u] = time
time += 1
while len(S) != 0:
u = S[-1]
if len(adj_list[u]) != 0:
v = adj_list[u].popleft()
if color[v] == "W":... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,203 |
s830036416 | p02238 | u258049727 | 1585806712 | Python | Python3 | py | Accepted | 20 | 5792 | 511 | n = int(input())
M = [[0]*n for _ in range(n)]
st = [0]*n
d = [0]*n
f = [0]*n
tt = 0
def dfs(u,t):
st[u] = 1
t += 1
d[u] = t
for v in range(n):
if M[u][v] == 0: continue
if st[v] == 0: t = dfs(v,t)
st[u] = 2
t += 1
f[u] = t
return t
for _ in range(n):
i = [int(i) fo... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,204 |
s735817332 | p02238 | u838900850 | 1585668526 | Python | Python3 | py | Accepted | 20 | 5720 | 614 | def main():
inf = 1000000007
n = int(input())
e = [[] for _ in range(n)]
d = [inf]*n
f = [inf]*n
step = 1
def dfs(v):
nonlocal step
d[v] = step
step+=1
for u in e[v]:
if d[u] == inf:dfs(u)
f[v] = step
step +=1
e = [[] for _ i... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,205 |
s633594580 | p02238 | u622912304 | 1585663756 | Python | Python3 | py | Accepted | 20 | 5668 | 595 | # https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/11/ALDS1_11_B
G = {}
d = {}
f = {}
used = set()
t = 1
def dfs(cur):
global G, d, f, t
used.add(cur)
d[cur] = t
for i in G[cur]:
if i in used:
continue
t += 1
dfs(i)
t += 1
f[cur] = t
if __name__ ... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,206 |
s766968204 | p02238 | u037820925 | 1585450714 | Python | Python3 | py | Accepted | 20 | 5660 | 507 | n = int(input())
a = [None]
for i in range(n):
adj = list(map(int,input().split()))
a.append(adj[2:])
s = [None]
for i in range(1, n + 1):
s.append([False, i])
time = 0
def dfs(u):
global time
s[u][0] = True
time += 1
s[u].append(time)
for v in a[u]:
if s[v][0] ==... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,207 |
s630595716 | p02238 | u951319620 | 1585402573 | Python | Python3 | py | Accepted | 50 | 9108 | 842 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
n = ni()
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,208 |
s321742316 | p02238 | u665008200 | 1585388562 | Python | Python3 | py | Accepted | 20 | 5656 | 551 | def inpl():
return list(map(int, input().split()))
def dfs(v, step):
if f[v] != -1:
return step
f[v] = step
step += 1
for nv in E[v]:
# print("now", v, nv, step)
step = dfs(nv - 1, step)
d[v] = step
return step + 1
n = int(input())
E = [[] for i in range(n)]
for _... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,209 |
s588795156 | p02238 | u176870835 | 1585384877 | Python | Python3 | py | Accepted | 20 | 5656 | 493 | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(15000)
n = int(sys.stdin.readline())
ret = []
inp = sys.stdin.readlines()
G = [None]*(n)
d = [0]*(n)
f = [0]*(n)
def dfs(i,t):
if d[i] != 0:
return t
t = t+1
d[i] = t
for j in G[i]:
t = dfs(j,t)
f[i] = t+1
return f[i]
for i in range(n):
v = ... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,210 |
s147539315 | p02238 | u902441874 | 1585361676 | Python | Python3 | py | Accepted | 20 | 5624 | 802 | # 隣接リスト
n = int(input())
graph = []
for _ in range(n):
tmp = list(map(int, input().split()))
if tmp[1] == 0:
graph.append([])
else:
graph.append(tmp[2:])
#print(graph)
check = [0]*n
count = 0
go = [0]*n
back = [0]*n
def dfs(v):
#print(v)
global count
if check[v] == 0:
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,211 |
s825819402 | p02238 | u560613143 | 1585299494 | Python | Python3 | py | Accepted | 20 | 6052 | 916 | n=int(input())
G=[]
for i in range(n):
u,k,*l=map(int,input().split())
G.append(l)
#print(G)
log_finish=[0]*n
log_start=[0]*n
from collections import deque
def dfs(G):
q=deque()
for i in range(n,0,-1):
q.append((i,-1,0))
log_finish[0]=1
log_start[0]=1
cnt=0
while q:
#pri... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,212 |
s885597628 | p02238 | u942920884 | 1585218065 | Python | Python3 | py | Accepted | 20 | 5628 | 572 | def dfs(v, u=0):
global n, t, d, f, reached
if len(reached) == n:
return
d[u] = t
t += 1
reached.add(u + 1)
for ui in range(v[u][1]):
next = v[u][2 + ui]
if next in reached:
continue
dfs(v, next - 1)
f[u] = t
t += 1
n = int(input())
v = []... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,213 |
s827490436 | p02238 | u044232230 | 1585145357 | Python | Python3 | py | Accepted | 20 | 5712 | 646 | # DFS(再帰) v:頂点
def DFS(v,dis,fin):
global time
# 訪問したので発見時刻を記入
dis[v] = time
time += 1
# vに隣接している頂点をみる
for u in V[v]:
if dis[u] is None:
DFS(u,dis,fin)
# 処理が完了したので完了時刻を記入
fin[v] = time
time += 1
n = int(input())
# 0番目を始点として初期化
V = [[i for i in range(n)]]
for i in range(n):
_, __,... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,214 |
s092290175 | p02238 | u705234550 | 1585013754 | Python | Python3 | py | Accepted | 20 | 5644 | 2,545 | n = int(input())
A = [[] for i in range(n)]
for i in range(n):
A[i] = list(map(int, input().split()))
B = [[0 for i in range(2)] for j in range(n)]
order = []
time = 0
def dfs(n, num):
global time
while time < 2*n:
a = num
time += 1
if B[num-1][0] == 0: # まだ発見していないとき
if A[num-1][1] != 0: # ... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,215 |
s602776344 | p02238 | u260266858 | 1584963455 | Python | Python3 | py | Accepted | 20 | 5660 | 566 | G = {}
N = int(input())
for _ in range(N):
L = list(map(int, input().split()))
G[L[0]] = L[2:]
# print(G)
d = [-1] * N
f = [-1] * N
q = [1]
visited = [False] * N
time = 1
def dfs(v):
global time
visited[v-1] = True
for nv in G[v]:
if d[nv-1] < 0:
d[nv-1] = time
t... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,216 |
s000366234 | p02238 | u165564808 | 1584871690 | Python | Python3 | py | Accepted | 20 | 5644 | 2,374 | NOT_FOUND = 0
FOUND = 1
FINISHED = 2
class Stack(object):
def __init__(self):
self._stack = []
def push(self, val):
self._stack.append(val)
def pop(self):
val = self._stack[-1]
del self._stack[-1]
return val
def top(self):
if len(self._stack) > 0:
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,217 |
s908068805 | p02238 | u009853378 | 1584867072 | Python | Python3 | py | Accepted | 20 | 5668 | 894 | ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
class tree:
def __init__(self,n):
self.n = n
self.vlist = [None]*self.n
self.start = [None]*self.n
self.finish = [None]*self.n
self.time = 0
def add(self,n... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,218 |
s619711432 | p02238 | u566160059 | 1584684975 | Python | Python3 | py | Accepted | 60 | 7416 | 2,437 | from typing import List
def alds_1_11a():
n = int(input())
for i in range(n):
u, k, *v = map(int, input().split())
a = [0] * n
for i_v in v:
index_v = i_v - 1
a[index_v] = 1
print(*a)
return
def print_matrices_list(matrices_list):
for index_row... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,219 |
s356240178 | p02238 | u920279959 | 1584516530 | Python | Python3 | py | Accepted | 20 | 5660 | 530 | n = int(input())
E = [[]]*n
for i in range(n):
inputs = list(map(int, input().split()))
if inputs[1]==0:
continue
else:
for j in inputs[2:]:
E[i] = E[i] + [j-1]
beg = [-1]*n
fin = [-1]*n
t = 0
def f(i):
global t
#print(i,t)
t += 1
beg[i] = t
for c i... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,220 |
s045608745 | p02238 | u230072054 | 1584421862 | Python | Python3 | py | Accepted | 30 | 6412 | 1,069 | import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
global current_time
global visited,go_time,back_time
global G
def dfs(node_id):
global current_time #書かないとローカル変数扱いされる
go_time[n... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,221 |
s753440994 | p02238 | u802742860 | 1584360278 | Python | Python3 | py | Accepted | 50 | 9012 | 856 | import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect
MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 8)
n = int(input())
i... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,222 |
s536781062 | p02238 | u217435805 | 1584316110 | Python | Python3 | py | Accepted | 30 | 5748 | 938 | import sys
# sys.stdin = open('input.txt')
def fillMatrix():
for i in range(n):
u, k, *v = map(int, input().split())
for j in v:
matrix[i][j-1] = 1
def dfs(u):
global time
status[u] = VISITING
time += 1
discoverTime[u] = time
for v in range(n):
if matrix[u][... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,223 |
s952946554 | p02238 | u610816226 | 1584182835 | Python | Python3 | py | Accepted | 30 | 6108 | 592 | from collections import deque
n = int(input())
graph = [deque([]) for _ in range(n+1)]
ans = [[i, ] for i in range(n+1)]
for i in range(n):
u, k, *v = list(map(int, input().split()))
for j in v:
graph[u].append(j)
stack = deque()
stack.append(1)
marked = []
t = 0
def dfs(v):
global t
marked.append(v)
t +=... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,224 |
s314793625 | p02238 | u483082413 | 1584177813 | Python | Python3 | py | Accepted | 20 | 5716 | 836 | n = int(input())
points = []
seen = []
find_time = []
end_time = []
for _ in range(n):
input_text = list(map(int, input().split()))
u, k, v_list = input_text[0], input_text[1], input_text[2:]
seen.append(False)
points.append(v_list)
find_time.append(0)
end_time.append(0)
count = [0]
def dfs(... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,225 |
s396440414 | p02238 | u093588014 | 1584168603 | Python | Python3 | py | Accepted | 20 | 5716 | 546 | import sys
input = lambda: sys.stdin.readline().rstrip()
n=int(input())
s=0 ; st=set() ; ans=[[] for i in range(n)] ; v=0
def dfs(g,v):
global s,st,ans
if v in st: return
else: st.add(v)
s+=1
ans[v].append(s)
for i in g[v]:
dfs(g,i)
s+=1
ans[v].append(s)
g=[]
for _ in range(n):
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,226 |
s650269462 | p02238 | u284842807 | 1584111197 | Python | Python3 | py | Accepted | 20 | 5668 | 483 | import sys
sys.setrecursionlimit(2000000)
n = int(input())
m = [list(map(int, input().split()))[2:] for _ in range(n)]
def dfs(x, time):
first[x] = time
time += 1
for v in m[x]:
if first[v-1] == 0:
time = dfs(v-1, time)
finish[x] = time
time += 1
return time
first = [0] * ... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,227 |
s854802037 | p02238 | u076951214 | 1584066975 | Python | Python3 | py | Accepted | 20 | 5660 | 761 | # =============================================================================
# Depth First Search
# =============================================================================
import sys
sys.setrecursionlimit(10**8)
N=int(input())
Graph=[list(map(int,input().split()))[2:] for _ in range(N)]
Graph.insert(0,[])
see... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,228 |
s522384285 | p02238 | u853158149 | 1584042636 | Python | Python3 | py | Accepted | 30 | 6116 | 1,340 | #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdi... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,229 |
s979652486 | p02238 | u799595944 | 1583969101 | Python | Python3 | py | Accepted | 20 | 5632 | 597 | n = int(input())
V = [[] for _ in range(n)]
for i in range(n):
data = list(map(int, input().split(" ")))
V[i] = data[2:]
answer = [[None, None] for _ in range(n)]
counter = 1
def dfs(v):
global counter
if answer[v][0] == None:
answer[v][0] = counter
counter += 1
# ノードの子供の管理
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,230 |
s691265963 | p02238 | u457728280 | 1583766336 | Python | Python3 | py | Accepted | 20 | 5724 | 530 | def dfs(v, k):
if ans[v][1] == 0:
ans[v][1] = k
else:
return k - 1
for i in d[v]:
k = dfs(i, k + 1)
k += 1
if ans[v][2] == 0:
ans[v][2] = k
return k
G = int(input())
vlst = [list(map(int, input().split())) for _ in range(G)]
d = [[] for _ in range(G)]
for i in r... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,231 |
s366274696 | p02238 | u655589806 | 1583747420 | Python | Python3 | py | Accepted | 20 | 5660 | 561 | n = int(input())
d = [0]*(n+1)
f = [0]*(n+1)
t = 1
adjacent_list = [[] for _ in range(n+1)]
for i in range(n):
e = list(map(int,input().split()))
if e[1] != 0:
adjacent_list[i+1].extend(e[2:])
#print(adjacent_list)
def dfs(v):
if d[v] >= 1:
return
global t
if d[v] == 0: #未発見なら発見時刻... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,232 |
s987059706 | p02238 | u925219592 | 1583584128 | Python | Python3 | py | Accepted | 20 | 5716 | 529 | def depth_search(i, adj, d, f, t):
if d[i-1]:
return t
d[i-1] = t
t += 1
for v in adj[i-1]:
t = depth_search(v, adj, d, f, t)
f[i-1] = t
t += 1
return t
n = int(input())
adj = [list(map(int, inpu... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,233 |
s497394565 | p02238 | u942532706 | 1583507353 | Python | Python3 | py | Accepted | 30 | 6036 | 624 | from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N):
ls = list(map(int, input().split()))
u = ls[0] - 1
for v in ls[2:]:
G[u].append(v - 1)
time = 1
d = [None for _ in range(N)]
f = [None for _ in range(N)]
def dfs(v):... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,234 |
s093825044 | p02238 | u327242612 | 1583469170 | Python | Python3 | py | Accepted | 20 | 5748 | 1,157 | if __name__ == '__main__':
from sys import stdin
input = stdin.readline
N = 100
WHITE = 0
GRAY = 1
BLACK = 2
M = [[0]*N for _ in range(N)]
color = [WHITE]*N # colorの初期化は最初に行っておく。
d = [0]*N
f = [0]*N
def dfs_visit(u):
global tt
color[u] = GRAY
tt +=... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,235 |
s765472046 | p02238 | u240839092 | 1582730906 | Python | Python3 | py | Accepted | 20 | 5628 | 1,766 | def main():
"""有向グラフの深さ優先探索
Note: V[i]は頂点iから通じる頂点の集合を意味するが,
V[i]: {i}とV[i]: Noneは同値とされている。
"""
stack = []
passed_lines = []
n = int(input())
V = [None]*(n+1)
D = [None]*(n+1)
F = [None]*(n+1)
passed_vertices = set()
vertices = set(range(1, n+1))
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,236 |
s294957295 | p02238 | u440554255 | 1582648796 | Python | Python3 | py | Accepted | 20 | 5720 | 484 | n = int(input())
graph = {}
for _ in range(n):
i = list(map(int,input().split()))
graph[i[0]] = i[2:]
first = {i:0 for i in range(1,n+1)}
last = {i:0 for i in range(1,n+1)}
seen = set()
time = 1
def dfs(v):
global time
seen.add(v)
first[v] = time
time += 1
for nxt in graph[v]:
if nxt in seen:
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,237 |
s193139380 | p02238 | u350045793 | 1582626129 | Python | Python3 | py | Accepted | 20 | 5648 | 528 | N = int(input())
adj_list = []
for _ in range(N):
line = list(input().split(" "))
adj_list.append([int(k) - 1 for k in line[2:]])
d = [-1 for _ in range(N)]
f = [-1 for _ in range(N)]
time = 1
visited = set()
def dfs(p):
global time
if p in visited:
return
d[p] = time
time += 1
v... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,238 |
s892340200 | p02238 | u037175009 | 1582551351 | Python | Python3 | py | Accepted | 20 | 5668 | 537 | import sys
input = sys.stdin.readline
d = []
f = []
time = 0
def search(r):
global d,f,time,s
if d[r] == 0:
time += 1
d[r] = time
else:
return
for x in s[r]:
search(x)
time += 1
f[r] = time
n = int(input())
s = [[] for i in range(n+1)]
for _ in range(n):
d =... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,239 |
s070788930 | p02238 | u989573662 | 1582421923 | Python | Python3 | py | Accepted | 30 | 6192 | 984 | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collection... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,240 |
s830043225 | p02238 | u766183517 | 1582302419 | Python | Python3 | py | Accepted | 50 | 9116 | 1,314 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,241 |
s937732598 | p02238 | u670802622 | 1582283775 | Python | Python3 | py | Accepted | 30 | 6108 | 927 | # Depth First Search
from collections import deque
N = int(input())
nodes = []
G ={}
is_visited = {}
for _ in range(N):
lst = list(map(int, input().split()))
idx = lst[0]
nodes.append(idx)
is_visited[idx] = False
degree = lst[1]
if degree > 0:
G[idx] = lst[2:]
else:
G[idx] ... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,242 |
s979550329 | p02238 | u924675516 | 1580873466 | Python | Python3 | py | Accepted | 40 | 6408 | 2,095 | #!/usr/bin/env python3
from enum import Enum
class DFS():
class Color(Enum):
WHITE = 0
GRAY = 1
BLACK = 2
def __init__(self, M, n):
self.M = M
self.n = n
self.color = [self.Color.WHITE for _ in range(self.n)]
self.d, self.f = [-1] * self.n, [-1] * self.... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,243 |
s429911454 | p02238 | u299931928 | 1580430024 | Python | Python3 | py | Accepted | 30 | 6184 | 1,200 | # -*- coding: utf-8 -*-
'''
所要時間は、分位であった。
'''
# ライブラリのインポート
#import re
import sys
input = sys.stdin.readline
#import heapq
#import bisect
import collections
#import math
global time, Ls, Lf, E,LG,c,n
time = 1
def main():
global time, Ls, Lf, E, LG,c,n
c = 0
n = int(input().strip())
E = [[] for _ in r... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,244 |
s457715029 | p02238 | u079849541 | 1580364022 | Python | Python3 | py | Accepted | 30 | 5640 | 543 | def disc(s,d):
ans[d][0] = s
s += 1
if main[d][0] != 0:
for l in range(1,int(main[d][0])+1):
if ans[int(main[d][l])-1][0] == 0:
s = disc(int(s),int(main[d][l])-1)
ans[d][1] = s
return s+1
n = int(input())
main = []
for i in range(n):
a = input().split()
if int(a[1]) > 0:
main.append(a[1:])
else:
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,245 |
s182942936 | p02238 | u369455271 | 1579762322 | Python | Python3 | py | Accepted | 20 | 5672 | 1,652 | class Node:
def __init__(self):
self.distime = 0
self.fintime = 0
def input_data(self, nodes):
data = input().split()
self.number = int(data[0])
self.v = [nodes[int(x) - 1] for x in data[2:]]
@property
def status(self):
return bool(self.distime) + bool(... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,246 |
s381415643 | p02238 | u230220367 | 1579369038 | Python | Python3 | py | Accepted | 30 | 6052 | 1,231 | from collections import deque
#スタックを使った深さ優先探索の実装
l = int(input())
rlist = []
for i in range(l):
li = list(map(int, input().split()))
rlist.append(deque([ll-1 for ll in li[2:]]))
color = ['white'] * l
find_time = [0] * l
stop_time = [0] * l
stack = []
time = 0
def dfs(u):
global time
stack.append(u)... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,247 |
s131499163 | p02238 | u221424603 | 1577706911 | Python | Python3 | py | Accepted | 20 | 5712 | 909 | n=int(input())
G=[[j for j in range(n)] for i in range(n)]
for i in range(n):
g_in=list(map(int,input().split()))
u=g_in[0]
k=g_in[1]
v=g_in[2:]
for j in v:
G[u-1][j-1]=1
visited=[0 for i in range(n)]
finished=[0 for i in range(n)]
L=[]
out=[[i+1,0,0] for i in range(n)]
step=0
def dfs(cn):... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,248 |
s564677463 | p02238 | u194126754 | 1577431650 | Python | Python3 | py | Accepted | 20 | 5716 | 1,235 | N = int(input())
DG={} # それぞれのnodeが持つ隣接リストを、キーをnodeにして管理
node_ls=[]
is_visited={} # 訪れたかどうかを、nodeをキーに辞書で管理
# 有向グラフをディクトで管理することにする
for _ in range(N):
tmp = input().split()
node_id = tmp[0]
node_ls.append(node_id) # 1~n の順番
is_visited[node_id] = False # 訪れた時にTrueにする
adj_num = int(tmp[1]) ... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,249 |
s659849161 | p02238 | u529459816 | 1576676672 | Python | Python3 | py | Accepted | 30 | 6060 | 1,556 | from collections import deque
def conv_list(n):
adj_matrix = []
for _ in range(n):
adj_list = input().split()
adj_list = list(map(int, adj_list))
adj_row = [False] * n
if adj_list[1] > 0:
for i in adj_list[2:]:
adj_row[i - 1] = True
adj_matri... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,250 |
s123196522 | p02238 | u794140916 | 1575948405 | Python | Python3 | py | Accepted | 20 | 5824 | 882 |
WHITE = 0
GRAY = 1
BLACK = 2
NIL = -1
def dfs(u):
global time
color[i] = GRAY
time += 1
d[u] = time
for v in range(n):
if m[u][v] and (color[v] == WHITE):
dfs(v)
color[u] = BLACK
time += 1
f[u] = time
def next(u):
for v in range(nt[u], n + 1):
nt... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,251 |
s221859886 | p02238 | u504636463 | 1575294040 | Python | Python3 | py | Accepted | 20 | 5704 | 1,259 | if __name__ == '__main__':
n = int(input())
graph = [[0 for i in range(n)] for _ in range(n)]
frist = [0 for _ in range(n)]
end = [0 for _ in range(n)]
visit = [False for _ in range(n)]
# get the group
for i in range(n):
datas = [int(num) for num in input().split(' ')]
if dat... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,252 |
s516157913 | p02238 | u793120772 | 1574165498 | Python | Python3 | py | Accepted | 20 | 5656 | 386 | N = int(input())
E = [None] * (N+1)
for _ in range(N):
u, k, *vs = list(map(int, input().split()))
E[u] = vs
d = [0] * (N+1)
f = [0] * (N+1)
t = 0
def dfs(v):
global t, d, f
if d[v]:
return
t += 1
d[v] = t
for u in E[v]:
dfs(u)
t += 1
f[v] = t
for v in range(1, N+... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,253 |
s791918884 | p02238 | u608189632 | 1573997615 | Python | Python3 | py | Accepted | 20 | 5764 | 1,176 |
def dfs_visit(u):
global n, M, d, f, time
if color[u] == 'WHITE':
color[u] = 'GRAY'
time += 1
d[u] = time
for v in range(n):
if M[u][v] == 0:
continue
if color[v] == 'WHITE':
dfs_visit(v)
color[u] = 'BLACK'
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,254 |
s326004291 | p02238 | u899624451 | 1573662077 | Python | Python3 | py | Accepted | 20 | 5716 | 566 | count = 0
def solve(i, a, ans):
global count
if ans[i][0] == 0:
count += 1
ans[i][0] = count
for x in range(a[i][1]):
if ans[a[i][2 + x] - 1][0] == 0:
solve(a[i][2 + x] - 1, a, ans)
if ans[i][1] == 0:
count += 1
ans[i][1] = count
N = int(input())... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,255 |
s479906220 | p02238 | u439083584 | 1573581909 | Python | Python3 | py | Accepted | 20 | 5648 | 537 | n=int(input())
E=[0]*n
for _ in range(n):
u,k,*V=map(int,input().split())
E[u-1]=sorted(V)[::-1]
todo=[1]
seen=[0]*n
d=[0]*n
f=[0]*n
t=0
while 0 in f:
if not todo:
todo.append(seen.index(0)+1)
if seen[todo[-1]-1]==0:
seen[todo[-1]-1]=1
t+=1
d[todo[-1]-1]=t
for... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,256 |
s424372875 | p02238 | u137240270 | 1572481618 | Python | Python3 | py | Accepted | 30 | 6096 | 884 | from collections import deque
N = 100
WHITE = 0
GRAY = 1
BLACK = 2
M = [[0 for _ in range(N)] for _ in range(N)]
color = [0 for _ in range(N)]
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]
nt = [0 for _ in range(N)]
tt = 0
def main():
n = int(input())
for _ in range(n):
u, k, *v_s = map(int, ... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,257 |
s183704767 | p02238 | u525329683 | 1572189865 | Python | Python3 | py | Accepted | 30 | 5716 | 1,226 | # https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/11/ALDS1_11_B
# 本の解説通りかは知らない
# データの読み込み
N = int(input())
DG = {}
node_ls = []
is_visited = {}
# 有向グラフをディクトで管理することにする
for _ in range(N):
tmp = input().split()
node_id = tmp[0]
node_ls.append(node_id)
is_visited[node_id] = False
adj_num = int(... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,258 |
s826629191 | p02238 | u639928232 | 1571937342 | Python | Python3 | py | Accepted | 20 | 5808 | 573 | #!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
n = int(input())
G1 = [0]*n
G2 = [[0]*n for i in range(n)]
d = [0]*n
f = [0]*n
for i in range(n):
inp = tuple(map(int, input().split()))
G1[inp[0]-1]=sorted(inp[2:])
time=0
def dfs(vertex):
if d[vertex... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,259 |
s574316271 | p02238 | u121563294 | 1571386661 | Python | Python3 | py | Accepted | 20 | 5656 | 385 | N = int(input())
E = [None] * (N+1)
for _ in range(N):
u, k, *vs = list(map(int, input().split()))
E[u] = vs
d = [0] * (N+1)
f = [0] * (N+1)
t = 0
def dfs(v):
global t, d, f
if d[v]:
return
t += 1
d[v] = t
for u in E[v]:
dfs(u)
t += 1
f[v] = t
for v in range(1, N+... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,260 |
s238592604 | p02238 | u778781355 | 1571022849 | Python | Python3 | py | Accepted | 60 | 7280 | 685 | from typing import List
def DFS(G: List[int]):
global time
time = 0
n = len(G)
for u in range(n):
if color[u] == "WHITE":
DFS_Visit(u)
def DFS_Visit(u: int):
global time
color[u] = "GRAY"
time += 1
d[u] = time
for v in G[u]:
if color[v] == "WHITE":
pi[v] = u
DFS_Visit(v)
color[u] = "BLACK"
tim... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,261 |
s429324087 | p02238 | u153665391 | 1569726924 | Python | Python3 | py | Accepted | 30 | 6500 | 897 | from enum import Enum
class Color(Enum):
WHITE = 0
GRAY = 1
BLACK = 2
def dfs_visit(u, total_time):
colors[u] = Color.GRAY
total_time += 1
d[u] = total_time
stack.append(u)
for v in range(N):
if adj[u][v] == 1 and colors[v] == Color.WHITE:
total_time = dfs_visit(v, total_time)
colors[u] = ... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,262 |
s509840276 | p02238 | u134521115 | 1569298023 | Python | Python3 | py | Accepted | 20 | 5748 | 801 | import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
global time
time = 0
def dfs(u: int, visited: list, d: list, f: list, M: list, n: int):
global time
visited[u] = True
time += 1
d[u] = time
for j in range(n):
if M[u][j] == 1 and not visited[j]:
dfs(j, visited, ... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,263 |
s012237335 | p02238 | u183700122 | 1568628306 | Python | Python3 | py | Accepted | 30 | 6096 | 553 | from collections import deque
def dfs(v):
global t
d[v] = t
visited[v] = True
t += 1
for u in graph[v]:
if not visited[u]: dfs(u)
f[v] = t
t += 1
n = int(input())
graph = [deque() for i in range(n)]
visited = [False] * n
d = [0] * n
f = [0] * n
t = 1
for i in r... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,264 |
s189864667 | p02238 | u482227082 | 1568205591 | Python | Python3 | py | Accepted | 20 | 5692 | 904 | import sys
def input():
return sys.stdin.readline().rstrip()
def dfs(c, n, G, ans):
count = c
for i, flag in enumerate(G[n]):
if flag == 1 and ans[i][0] == 0:
count += 1
ans[i][0] = i + 1
ans[i][1] = count
ans[i][2] = dfs(count, i, G, ans)
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,265 |
s510791178 | p02238 | u182175955 | 1568190624 | Python | Python3 | py | Accepted | 20 | 5644 | 767 | #連結グラフではない
n = int(input())
V = [[] for _ in range(n+1)]
for _ in range(n):
inpt = list(map(int,input().split( )))
if len(inpt)>2:
V[inpt[0]] = inpt[2:]
D = [0]*(n+1)
F = [0]*(n+1)
time = 1
Q = [1]
D[0] = -1
D[1] = 1
while len(Q) > 0 or 0 in D[1:]:
v = Q[-1]
remains = False
for i in V[v]:... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,266 |
s853671153 | p02238 | u631142478 | 1566498284 | Python | Python3 | py | Accepted | 20 | 5640 | 976 | def main():
n = int(input())
_next, state, d, f = [], [False] * n, [0] * n, [0] * n
for _ in range(n):
u, k, *v = map(lambda s: int(s) - 1, input().split())
_next.append(sorted(v, reverse=True))
stack = []
time = 0
while True:
for i in range(n):
if not state[... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,267 |
s875668756 | p02238 | u784856415 | 1566399125 | Python | Python3 | py | Accepted | 20 | 5728 | 863 | #import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy
setrecursionlimit(10**6)
#@pysno... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,268 |
s072169623 | p02238 | u817810878 | 1564993654 | Python | Python3 | py | Accepted | 60 | 7356 | 1,093 | from typing import List
def dfs(adj_matrix: List[List[int]], vartex: int) -> int:
global step
global discover_times
global finish_times
if 0 != discover_times[vartex]:
return 0
discover_times[vartex] = step
for col_idx in range(len(adj_matrix)):
if (0 != adj_matrix[vartex][col... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,269 |
s573895673 | p02238 | u470586273 | 1564886873 | Python | Python3 | py | Accepted | 20 | 5664 | 390 | def dfs(v,t):
d[v]=t
t+=1
for i in edge[v]:
if d[i]==-1:
t=dfs(i,t)
f[v]=t
t+=1
return t
n=int(input())
edge=[[] for _ in range(n)]
for _ in range(n):
u,_,*v=map(lambda x:int(x)-1,input().split())
edge[u]=sorted(v)
d,f=[-1]*n,[-1]*n
k=1
for i in range(n):
if d[i]... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,270 |
s538674584 | p02238 | u371539389 | 1562845383 | Python | Python3 | py | Accepted | 20 | 5664 | 723 | n = int(input())
l = [[] for i in range(n)]
class V:
def __init__(self, node):
self.d = -1
self.f = -1
self.node = node
for i in range(n):
_input = [int(j) - 1 for j in input().split(" ")]
u = _input[0]
k = _input[1] + 1
node = sorted(_input[2::])
if u in node:
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,271 |
s791566623 | p02238 | u638043175 | 1562765290 | Python | Python3 | py | Accepted | 20 | 5640 | 626 | import sys
input = sys.stdin.readline
v = []
tl = []
t = 1
def rec(node):
global t, tl, v
if tl[node-1][0] != -1:
# print("ret", node, tl[node-1][0])
return
tl[node-1][0] = t
t += 1
# print("t: {}", t)
adj = v[node-1][2:]
# print("adj: ", adj)
for i in adj:
rec(v[i-1][0])
tl[node-1][1] = t
t += 1
def ... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,272 |
s179243005 | p02238 | u357267874 | 1562376143 | Python | Python3 | py | Accepted | 20 | 5796 | 1,317 | n = int(input())
A = [[0] * n for _ in range(n)]
for _ in range(n):
u, k, *v = list(map(int, input().split()))
for j in v:
A[u-1][j-1] = 1
# for row in A:
# print(' '.join(list(map(str,row))))
t = 0
d = [None] * n
f = [None] * n
def dfs_recursive(u):
global t
t += 1
d[u] = t
for... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,273 |
s704027517 | p02238 | u135880652 | 1561770176 | Python | Python3 | py | Accepted | 20 | 5748 | 737 | WHITE = 0
GRAY = 1
BLACK = 2
n = int(input())
M = [[0] * n for i in range(n)]
d = [0] * (n)
f = [0] * (n)
color = [WHITE] * (n)
time = 0
def dfs_visit(u):
global time
time += 1
color[u] = GRAY
d[u] = time
for v in range(n):
if M[u][v] == 0:
continue
if color[v] == W... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,274 |
s218774885 | p02238 | u902579831 | 1561554411 | Python | Python3 | py | Accepted | 20 | 5788 | 781 | INTERVAL = 1
WHITE = 0
GRAY = 1
BLACK = 2
def depth_first_search(u):
global time
time += INTERVAL
d[u] += time
color[u] = GRAY
for v in range(n):
if matrix[u][v] and color[v] == WHITE:
depth_first_search(v)
time += INTERVAL
f[u] += time
color[u] = BLACK
# INPUT
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,275 |
s922313587 | p02238 | u026821956 | 1561457031 | Python | Python3 | py | Accepted | 20 | 5780 | 510 | n = int(input())
G = []
for i in range(n):
T = [0]*n
G.append(T)
for i in range(n):
L = list(map(int,input().split()))
for j in range(2,len(L)):
G[i][L[j]-1] += 1
time = 1
D = [-1]*n
F = [-1]*n
def dfs(src):
global time
D[src] = time
time += 1
for dst in range(n):
if G[sr... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,276 |
s676092991 | p02238 | u010611609 | 1561445579 | Python | Python3 | py | Accepted | 20 | 5628 | 486 | n = int(input())
al = [list(map(lambda s: int(s) - 1, input().split()))[2:] for _ in range(n)]
begin = [-1] * n
end = [-1] * n
not_visited = list(range(n))
t = 1
def dfs(u):
global begin, end, t, not_visited
begin[u] = t
t += 1
not_visited.remove(u)
for v in al[u]:
if begin[v] == -1:
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,277 |
s029099746 | p02238 | u481944101 | 1561387932 | Python | Python3 | py | Accepted | 20 | 5712 | 561 | n=int(input())
ne=[[] for _ in range(n+1)]
for _ in range(n):
u,k,*v=map(int,input().split())
ne[u]=v
class dfs:
def __init__(self, n, ne):
self.n=n
self.ne=ne
self.d=[0]*(n+1)
self.f=[0]*(n+1)
self.t=0
def search(self, a):
self.t+=1
self.d[a]=sel... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,278 |
s673189064 | p02238 | u772853944 | 1561373229 | Python | Python3 | py | Accepted | 20 | 5660 | 455 | n=int(input())
v=[[]]*n
for i in range(n):
tmp=list(map(int,input().split()))
tmp=[i-1 for i in tmp[2:]]
v[i]=tmp
time=1
D=[-1 for _ in range(n)]
F=[-1 for _ in range(n)]
def dfs(src):
global time
D[src]=time
time+=1
for dst in v[src]:
if D[dst]==-1:#未訪問
dfs(dst)
F... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,279 |
s933613183 | p02238 | u694199042 | 1559639885 | Python | Python3 | py | Accepted | 20 | 5720 | 463 | n = int(input())
adj = [ [] for _ in range (n) ]
for i in range(n):
_, _, *adj[i] = list(map(int, input().split()))
d = [0] * n
f = [0] * n
flag = [0] * n
time = 0
def dfs(u):
global time
time += 1
flag[u-1] = 1
d[u-1] = time
for v in adj[u-1]:
if flag[v-1] == 0:
dfs... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,280 |
s972726494 | p02238 | u350698365 | 1558352416 | Python | Python3 | py | Accepted | 30 | 6372 | 1,016 | # vim: set fileencoding=utf-8:
import sys
from functools import lru_cache
n = int(sys.stdin.readline().rstrip())
graph = [[0] * (n+1) for _ in range(n+1)]
for i in range(1, n+1):
tmp = [int(ele) for ele in sys.stdin.readline().rstrip().split()]
for j in tmp[2:]:
graph[i][j] = 1
d = [-1] * (n+1)
f = [-... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,281 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.