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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s942989988 | p02238 | u733357255 | 1597276465 | Python | Python3 | py | Accepted | 20 | 5660 | 485 | def dfs(i,cnt):
d[i] = cnt
cnt += 1
for j in edge[i]:
if d[j] == -1:
cnt = dfs(j,cnt)
f[i] = cnt
cnt += 1
return cnt
n = int(input())
edge = [[] for i in range(n)]
for not_used in range(n):
of_children, not_used, *v = map(lambda x: int(x)-1,input().split())
edge[of_c... | 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,082 |
s860669908 | p02238 | u793520502 | 1597041452 | Python | Python3 | py | Accepted | 30 | 6132 | 682 | import sys
input = sys.stdin.readline
from collections import deque
S = deque([])
def getNeighbor(A, i):
a = len(A)
for k in range(2, a):
M[i][A[k]-1] = 1
def dfs(u):
global t
t = t + 1
S.append(u)
c[u] = 1
d[u] = t
for v in range(n):
if M[u][v] and c[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,083 |
s120159971 | p02238 | u828164095 | 1596879127 | Python | Python3 | py | Accepted | 30 | 5636 | 890 | n = int(input())
adjacency_list = []
for i in range(n):
input_list = list(map(int, input().split()))
adjacency_list.append(input_list[2:])
checked_set = set()
dfs_stack = []
v =[0 for i in range(n)]
f =[0 for i in range(n)]
time = 1
for i in range(n):
if i not in checked_set:
dfs_stack = []
... | 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,084 |
s283133302 | p02238 | u849721539 | 1596804475 | Python | Python3 | py | Accepted | 30 | 6056 | 738 | N=int(input())
L=[[10**9]for i in range(N+1)]
for i in range(N):
l=list(map(int,input().split()))
for j in range(l[1]):
L[i+1].append(l[2+j])
#print(L)
for i in range(N+1):
L[i].sort(reverse=True)
#print(L)
ans=[]
for i in range(N+1):
ans.append([0,0])
from collections import deque
Q=de... | 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,085 |
s160769904 | p02238 | u512068851 | 1596725647 | Python | Python3 | py | Accepted | 20 | 5716 | 600 | d_num = int(input())
graph = [[] for _ in range(d_num+1)]
for _ in range(d_num):
u, k, *neighbors = map(int, input().split())
graph[u] = neighbors
visited = set()
timestamps = [None for _ in range(d_num+1)]
def dfs(u, stmp):
visited.add(u)
entry = stmp
stmp += 1
for v in graph[u]:
if... | 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,086 |
s690750850 | p02238 | u210251354 | 1596688194 | Python | Python3 | py | Accepted | 20 | 5752 | 1,283 | from sys import stdin
input = stdin.readline
N = 100
WHITE = 0 # 未訪問
GRAY = 1 # 訪問したが、スタックに残っている
BLACK = 2 # 訪問完了済み
M = [[0]*N for _ in range(N)] # n*nの隣接行列の作成
color = [WHITE]*N # colorの初期化
d = [0]*N # 最初の訪問時刻のタイムスタンプ
f = [0]*N # 完了時刻のタイムスタンプ
def dfs_visit(u): # uの訪問処理
global tt
color[u] = GRAY
tt += 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,087 |
s751393751 | p02238 | u914515588 | 1596551215 | Python | Python3 | py | Accepted | 40 | 7260 | 1,681 | import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = ... | 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,088 |
s502198613 | p02238 | u104259918 | 1596200900 | Python | Python3 | py | Accepted | 20 | 5724 | 649 | # -*- coding: utf-8 -*-
# 標準入力を取得
n = int(input())
G = {}
for _ in range(n):
g = list(map(int, input().split()))
G[g[0]] = g[2:]
# 求解処理
seen = [False for _ in range(n)]
ans = []
def dfs(v: int) -> None:
seen[v - 1] = True
ans.append(v)
for w in G[v]:
if not seen[w - 1]:
dfs(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,089 |
s357529971 | p02238 | u204119336 | 1596177608 | Python | Python3 | py | Accepted | 20 | 5656 | 532 | # N=4
# G=[[2],[4],[],[3]]
import sys
sys.setrecursionlimit(1000000)
N=int(input())
G=[list(map(int, input().split()))[2:] for _ in range(N)]
v=[False]*N
d=[0]*N
f=[0]*N
timecount=1
def dfs(i):
global timecount
if v[i] : return
v[i] = True
d[i] = timecount
# print("D",i+1,timecount)
timecount... | 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,090 |
s413943522 | p02238 | u439569116 | 1595900869 | Python | Python3 | py | Accepted | 30 | 6088 | 909 | 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)
time = 0
arrive_time = [-1] * (N + 1)
finish_time = [-1] * (N + 1)
def dfs(v):
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,091 |
s705399927 | p02238 | u145526353 | 1595575130 | Python | Python3 | py | Accepted | 30 | 5668 | 676 | import sys
sys.setrecursionlimit(10 ** 8)
n = int(input())
graph = [[] for _ in range(n)]
for i in range(n):
graph[i] = list(map(lambda x: x - 1, list(map(int, input().split()))[2:]))
timestamp = [[] for _ in range(n)]
visited = [False] * n
cnt = 0
def dfs(v):
global visited
global cnt
global times... | 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,092 |
s350648476 | p02238 | u491421284 | 1595486467 | Python | Python3 | py | Accepted | 20 | 5624 | 1,258 | n = int(input())
class Node:
def __init__(self, idd, neighbors):
self.idd = idd
self.neighbors = neighbors
self.foundAt = 0
self.completeAt = 0
def __repr__(self):
return "{0} {1} {2}".format(self.idd, self.foundAt, self.completeAt)
Nodes = [None] * n
for i in ... | 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,093 |
s418877284 | p02238 | u525205447 | 1595420060 | Python | Python3 | py | Accepted | 20 | 5668 | 454 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(input())
G = [list(map(lambda x: int(x)-1, input().split()))[2:] for _ in range(N)]
D = [-1]*N
D2 = [-1]*N
def dfs(cur, now):
if D[cur] != -1: return now
now += 1
D[cur] = now
for nex in G[cur]:
now = dfs(nex,now)
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,094 |
s809830368 | p02238 | u258473357 | 1595201197 | Python | Python3 | py | Accepted | 20 | 5776 | 1,835 | # coding: utf-8
import itertools
import math
import bisect
class Node:
def __init__(self, id, next, rest):
self.id = id
self.before = None
self.next = next
self.rest = rest
self.d = None
self.f = None
def update_next(self):
self.next = first(self.rest)
... | 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,095 |
s193236811 | p02238 | u048101135 | 1595162026 | Python | Python3 | py | Accepted | 20 | 5652 | 950 | # coding: utf-8
# Your code here!
n = int(input())
M = []
for i in range(n):
adj = list(map(int,input().split()))
if adj[1] == 0:
M += [[]]
else:
M += [adj[2:]]
time = 1
ans = [[j+1,0,0] for j in range(n)] # id d f
while True:
for i in range(n):
if ans[i][1] == 0:
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,096 |
s199456224 | p02238 | u820092408 | 1595150486 | Python | Python3 | py | Accepted | 20 | 5652 | 466 | n = int(input())
Adj = [[0]]
for _ in range(n):
Adj.append(list(map(int, input().split()))[2:])
visited = [False]*(n+1)
s = [0]*(n+1)
f = [0]*(n+1)
time = 0
def dfs(i):
global time
time += 1
s[i] = time
visited[i] = True
for j in Adj[i]:
if not visited[j]:
dfs(j)
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,097 |
s021860131 | p02238 | u842787189 | 1595119834 | Python | Python3 | py | Accepted | 20 | 5716 | 605 | n = int(input())
G = {i:[] for i in range(1, n+1)}
for _ in range(n):
ukv = list(map(int, input().split()))
u = ukv[0]
k = ukv[1]
for i in range(2, 2+k):
G[u].append(ukv[i])
d = [-1 for _ in range(n+1)]
f = [-1 for _ in range(n+1)]
counter = 0
def dfs(n):
global counter
counter... | 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,098 |
s555166111 | p02238 | u434132766 | 1595092429 | Python | Python3 | py | Accepted | 20 | 5712 | 602 | N = int(input())
Graph = {}
Node_list = []
visited = {}
d = {}
f = {}
t = 1
for i in range(N):
tmp = input().split()
id = tmp[0]
Node_list.append(id)
visited[id] = False
if int(tmp[1]) != 0:
Graph[id] = tmp[2:]
else:
Graph[id] = []
def dfs(node):
global t
if ... | 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,099 |
s423609180 | p02238 | u802474686 | 1595062083 | Python | Python3 | py | Accepted | 20 | 5628 | 508 | global graph
global seen
token=0
def dfs(i):
global token
token+=1
seen[i][0]=token
for x in graph[i]:
if seen[x][0]==0:
dfs(x)
token+=1
seen[i][1]=token
n=int(input())
graph=[None for _ in range(n+1)]
for i in range(n):
lst=list(map(int,input().split()))
graph[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,100 |
s012311612 | p02238 | u069030680 | 1594784321 | Python | Python3 | py | Accepted | 30 | 6076 | 934 | from collections import defaultdict
def dfs(edges, n, d, f, time):
if n in d:
return
time[0] += 1
d[n] = time[0]
for to in edges[n]:
dfs(edges, to, d, f, time)
time[0] += 1
f[n] = time[0]
N = int(input())
edges = defaultdict(list)
for _ in range(N):
l = 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,101 |
s209960920 | p02238 | u108855621 | 1594753701 | Python | Python3 | py | Accepted | 30 | 6044 | 855 | import sys
from collections import defaultdict
time = 1
def dfs(g, visited, start, ans):
global time
visited[start - 1] = True
ans[start - 1][0] = time
for e in g[start]:
if not visited[e - 1]:
time += 1
dfs(g, visited, e, ans)
time += 1
ans[start - 1][1] = ti... | 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,102 |
s526564316 | p02238 | u075087498 | 1594268281 | Python | Python3 | py | Accepted | 20 | 5716 | 387 | n=int(input())
edge=[[] for _ in range(n+1)]
for i in range(n):
v,k,*u=list(map(int,input().split()))
edge[v]=u
d=[0]*(n+1)
f=[0]*(n+1)
def dfs(now,t):
d[now]=t
vis.append(now)
for i in edge[now]:
if i not in vis:
t=dfs(i,t+1)
f[now]=t+1
return t+1
vis=[]
t=1
for i in range(1,n+1):
if i not in... | 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,103 |
s710664414 | p02238 | u748843150 | 1594223767 | Python | Python3 | py | Accepted | 20 | 5736 | 1,103 | stack=[]
n=int(input())
color=[]
graph={}
d_time=[]
f_time=[]
time=0
root=[i for i in range(1,n+1)]
for i in range(n):
tmp=list(map(int,input().split()))
graph[tmp[0]]=[0 for j in range(n+1)]
color=["white" for l in range(n+1)]
d_time=[0 for j in range(n+1)]
f_time=[0 for j in range(n+1)]
for k... | 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,104 |
s145690877 | p02238 | u879371540 | 1594202299 | Python | Python3 | py | Accepted | 20 | 6064 | 519 | from collections import defaultdict as dd
N = int(input())
graph = dd(list)
seen = dd(int)
u = []
d, f = dd(int), dd(int)
ts = 1
for _ in range(N):
info = list(map(int, input().split()))
u.append(info[0])
graph[info[0]] = info[2:]
def dfs(v):
global ts
d[v] = ts
ts += 1
seen[v] = 1
for next_v in gr... | 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,105 |
s943108579 | p02238 | u878424017 | 1594101853 | Python | Python3 | py | Accepted | 30 | 6088 | 750 | from collections import deque
n = int(input())
data = [None]*n
unvisited = [1]*n
for _ in range(n):
a,*b = map(int,input().split())
a -= 1
data[a] = deque([i-1 for i in b[1:]])
d = [-1]*n
f = [-1]*n
t = 0
dq = deque([])
for u in range(n):
if unvisited[u]:
dq.append(u)
unvisited[u] = 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,106 |
s054347731 | p02238 | u845612949 | 1594080504 | Python | Python3 | py | Accepted | 30 | 5784 | 4,243 | # http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4647653#1
import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
class Graph:
def __init__(self, n, dictated=False, decrement=True, edge=[]):
self.n = n
self.dictated = dictated
self.decrement = decrement
self.e... | 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,107 |
s892568314 | p02238 | u398903226 | 1594043666 | Python | Python3 | py | Accepted | 20 | 5656 | 880 | n = int(input()) # 点の総数
path = list() # path[p] : 点pから行ける点のリスト
path.append([])
for _ in range(n):
tmp = list(map(int, input().split())) # tmp[0]から行ける点はtmp[1]個あり、それはtmp[2:]
path.append(tmp[2:])
d = [0]*(n+1) # 最初に発見した時刻
f = [0]*(n+1) # 隣接リストを調べ終えた時刻
TIME = 0
def dfs(p, d, f):
global TIME
TIME += 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,108 |
s211945214 | p02238 | u626932242 | 1593872751 | Python | Python3 | py | Accepted | 20 | 5728 | 764 | import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
idx = 1
def resolve():
def dfs(v):
global idx
begin[v] = idx
idx += 1
for u in edge[v]:
if begin[u] != 0:
continue
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,109 |
s664375981 | p02238 | u757541954 | 1593788311 | Python | Python3 | py | Accepted | 30 | 6112 | 531 | from collections import defaultdict
def dfs(v, t):
if start[v] == 0:
start[v] = t
t += 1
else:
return t
for nv in graph[v]:
t = dfs(nv, t)
end[v] = t
t += 1
return t
n = int(input())
graph = defaultdict(list)
for _ in range(n):
u, k, *v = map(int, inp... | 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,110 |
s730933017 | p02238 | u357050809 | 1593766285 | Python | Python3 | py | Accepted | 20 | 5656 | 591 | N = int(input())
adj_list = [ [] for _ in range(N+1) ]
for _ in range(N):
lst = list(map(int,input().split()))
node = lst[0]
if lst[1] != 0:
adj_list[node] = lst[2:]
visited = [False] * (N+1)
arrived = [-1] * (N+1)
left = [-1] * (N+1)
time = 0
def dfs(node):
global time
arrived[node] = time
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,111 |
s557295479 | p02238 | u973203074 | 1593702340 | Python | Python3 | py | Accepted | 20 | 5660 | 485 | n = int(input())
link = {}
for i in range(n):
a = list(map(int, input().split()))
a.reverse()
u, k = a.pop(), a.pop()
link[u] = []
for j in range(k):
link[u] += [a.pop()]
d, f = {}, {}
t = 0
def dfs(u):
global t
t += 1
d[u] = t
for v in link[u]:
if v not in d: 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,112 |
s449488944 | p02238 | u917514663 | 1593436844 | Python | Python3 | py | Accepted | 20 | 5716 | 645 | def main():
n=int(input())
u,k,v=0,0,[[] for _ in range(n+1)]
for i in range(n):
l=list(map(int,input().split()))
u=l[0]
for j in l[2:]:
v[u].append(j)
d=[0]*(n+1)
f=[0]*(n+1)
def dfs(s,t):
d[s]=t
for i in v[s]:
if d[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,113 |
s872907139 | p02238 | u171087702 | 1593403158 | Python | Python3 | py | Accepted | 30 | 6044 | 1,026 | from collections import deque
n = int(input())
u = []
k = []
v = []
for i in range(n):
tmp = list(map(int, input().split()))
u.append(tmp[0])
k.append(tmp[1])
if tmp[1] != 0:
v.append(tmp[2:])
else:
v.append([])
check = [0]*n
intime = [0]*n
outtime = [0]*n
time = 1
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,114 |
s795092326 | p02238 | u621895578 | 1592915280 | Python | Python3 | py | Accepted | 20 | 5664 | 534 | n = int(input())
d = [0]*n
f = [0]*n
G = [[] for _ in range(n)]
for _ in range(n):
l = list(map(int, input().split()))
u, k = l[:2]
l = list(map(lambda x: x-1, l[2:]))
G[u-1] = l
timestamp = [i+1 for i in range(2*n)]
def dfs(node):
global d,f,G,timestamp
if d[node]>0:
return False
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,115 |
s730483297 | p02238 | u742290340 | 1592818192 | Python | Python3 | py | Accepted | 20 | 5656 | 386 | n=int(input())
g=[]
for i in range(n):
u,k,*varray= map(int,input().split())
g.append(varray)
time = 1
d= [-1]* n
f= [-1]* n
def dfs(src):
global time
d[src]= time
time+=1
for i in g[src]:
if d[i-1]== -1:
dfs(i-1)
f[src]= time
time+=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,116 |
s848224816 | p02238 | u515473089 | 1592816728 | Python | Python3 | py | Accepted | 20 | 5640 | 421 | n=int(input())
D=[0]*(n+1)
F=[0]*(n+1)
v=[[] for i in range(n+1)]
flg=True
t=1
for i in range(n):
a=list(map(int,input().split()))
v[a[0]]=sorted(a[2:])
def dfs(p):
global t
if D[p]!=0: return
D[p]=t
t+=1
for i in v[p]:
if D[i]==0: dfs(i)
F[p]=t
t+=1
while flg:
flg=False
for i in 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,117 |
s089609575 | p02238 | u903393228 | 1592816660 | Python | Python3 | py | Accepted | 20 | 5792 | 840 | N = int(input())
M = []
for i in range(N):
a = list(map(int,input().strip().split()))
b = [int(i+1 in a[2:]) for i in range(N)]
M.append(b)
time = 1
D = [-1 for _ in range(N)]
F = [-1 for _ in range(N)]
def dfs(src):
global time # 関数内でglobal変数の書き換えることを宣言
D[src] = time # 訪問時刻を記録
time += 1
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,118 |
s692343857 | p02238 | u921537862 | 1592814181 | Python | Python3 | py | Accepted | 20 | 5664 | 616 | import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
G = [[] for _ in range(105)]
begin = [-1] * 105
end = [-1] * 105
t = 1
def dfs(v):
global t
begin[v] = t
t += 1
for e in G[v]:
if begin[e] < 0:
dfs(e)
end[v] = t
t += 1
def main():
N = 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,119 |
s653394469 | p02238 | u420455834 | 1592726263 | Python | Python3 | py | Accepted | 30 | 6216 | 810 | import sys
import itertools
# import numpy as np
import time
import math
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(input())
adj = [[] for _ 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,120 |
s594195858 | p02238 | u040807768 | 1592661901 | Python | Python3 | py | Accepted | 30 | 5720 | 623 | N = int(input())
UKV = [list(map(int,input().split())) for _ in range(N)]
seen = [False]*N
first_time = [-1]*N
last_time = [-1]*N
time = 0
def dfs(G, v):
global seen
global first_time
global last_time
global time
seen[v-1] = True
time += 1
first_time[v-1] = time
for next_v in G[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,121 |
s198533366 | p02238 | u472664493 | 1592647311 | Python | Python3 | py | Accepted | 20 | 5664 | 462 | def dfs(v, cnt):
D[v] = cnt
cnt += 1
for c in edge[v]:
if D[c] == -1:
cnt = dfs(c, cnt)
F[v] = cnt
cnt += 1
return cnt
V = int(input())
edge = [[] for _ in range(V)]
for _ in range(V):
u, _, *v = map(lambda x: int(x)-1, input().split())
edge[u] = sorted(v)
D, F = [-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,122 |
s620906890 | p02238 | u926956536 | 1592485101 | Python | Python3 | py | Accepted | 20 | 5660 | 785 | n = int(input())
ukv = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(n)]
stack = []
visited = []
time = 0
d = [0] * (n + 1)
f = [0] * (n + 1)
for i in range(1, n + 1):
if i not in visited:
stack.append(i)
visited.append(i)
time += 1
d[i] = time
while stack:
... | 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,123 |
s194227427 | p02238 | u562030778 | 1592410422 | Python | Python3 | py | Accepted | 20 | 5660 | 873 | n=int(input())
G=[]
for i in range(n):
L=list(map(int,input().split()))
G.append(L[2:])
for j in range(len(G[-1])):
G[-1][j]-=1
Forder=[-1]*n
Lorder=[-1]*n
ptr=1
def dfs(v):
#print(v)
#print(G[v])
#print()
global ptr
Forder[v]=ptr
ptr+=1
for next in G[v]:
if 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,124 |
s580320830 | p02238 | u800829827 | 1592407215 | Python | Python3 | py | Accepted | 20 | 5616 | 1,229 | def readinput():
n=int(input())
nList=[]
for _ in range(n+1):
nList.append([])
for _ in range(n):
l=list(map(int,input().split()))
nList[l[0]]=l[2:]
return n,nList
WHITE=0
GRAY=1
BLACK=2
color=[]
d=[]
f=[]
_time=0
def dfs(u,nList):
global color
global d
global 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,125 |
s230034671 | p02238 | u057134693 | 1592320803 | Python | Python3 | py | Accepted | 30 | 6056 | 763 | # 24
# ALDS_11_B - 深さ優先探索
from collections import deque
n = int(input())
u_l = []
k_l = []
v_l = []
for i in range(n):
_in = input()
_v_l = []
for j,_ in enumerate(_in.split()):
if j == 0:
u_l.append(int(_))
elif j == 1:
k_l.append(int(_))
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,126 |
s920950453 | p02238 | u390052013 | 1592295114 | Python | Python3 | py | Accepted | 20 | 5660 | 819 | def solve(v, g, ans, time):
if ans[v]["found"] != 10**9:
return time
time += 1
# print(v + 1, time, file=sys.stderr)
ans[v]["found"] = time
for a in g[v]:
time = solve(a, g, ans, time)
time += 1
# print(v + 1, time, file=sys.stderr)
ans[v]["complete"] = time
return ti... | 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,127 |
s226834197 | p02238 | u593772041 | 1592231891 | Python | Python3 | py | Accepted | 20 | 5664 | 699 | #ALDS_11_B - 深さ優先探索
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)#再帰回数の上限
def DFS(u, cnt):
visited.add(u)
first_contact = cnt
cnt += 1
for nb in edge[u]:
if nb not in visited:
cnt = DFS(nb, cnt)
stamp[u] = first_contact, cnt
return cnt+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,128 |
s706679240 | p02238 | u528682978 | 1592128793 | Python | Python3 | py | Accepted | 20 | 5624 | 400 | def dfs(adjlist,v):
global d,f,t
d[v-1]=t
t+=1
for node in adjlist[v-1]:
if d[node-1]<0 and node>0:
dfs(adjlist,node)
f[v-1]=t
t+=1
n=int(input())
adjlist=[list(map(int,input().split()))[2:] for _ in range(n)]
d=[-1]*n
f=[-1]*n
t=1
for i in range(1,n):
if d[i-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,129 |
s498560806 | p02238 | u928664635 | 1591935365 | Python | Python3 | py | Accepted | 20 | 5652 | 579 | n = int(input())
G = [[] for i in range(n+1)] #G(i): 頂点iと隣接する頂点のlist
for i in range(n):
a = [int(i) for i in input().split()]
G[a[0]] = a[2:]
G[a[0]].sort()
d = [0] * (n+1)
f = [0] * (n+1)
seen = [0] * (n+1) #頂点iが訪問済みの場合 seen[i] = 1
t = 0
def dfs(s):
global t
seen[s] = 1
d[s] = t
for i in... | 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,130 |
s511549082 | p02238 | u476858890 | 1591887492 | Python | Python3 | py | Accepted | 20 | 5664 | 581 | from sys import setrecursionlimit
setrecursionlimit(10 ** 9)
n = int(input())
graph = []
for _ in range(n):
tmp = list(map(int, input().split()))
if tmp[1] == 0:
graph.append([])
continue
else:
graph.append(list(map(lambda x: x - 1, tmp[2: tmp[1] + 2])))
d = [-1] * n
f = [-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,131 |
s746237800 | p02238 | u210664395 | 1591874691 | Python | Python3 | py | Accepted | 20 | 5664 | 970 | def main():
import sys
N = int(sys.stdin.readline())
L1 = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
#print(L1)
edge = [[] for _ in range(N+1)]
for row in L1:
for ele in row[2:]:
edge[row[0]].append(ele)
#edge[ele].append(row[0])
#print(... | 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,132 |
s964170080 | p02238 | u917268609 | 1591792154 | Python | Python3 | py | Accepted | 20 | 5640 | 406 | t = 1
v, d, f = {}, {}, {}
def dfs(i):
global t, v, d, f
if i in d:
return
if i != 0:
d[i] = t
t += 1
for j in v[i]:
dfs(j)
if i != 0:
f[i] = t
t += 1
n = int(input())
v[0] = list(range(1, n+1))
for i in range(n):
tmp = list(map(int, input().split()))
v[tmp[0]] = tmp[2:]
v[tmp[... | 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,133 |
s778634630 | p02238 | u156732351 | 1591626124 | Python | Python3 | py | Accepted | 20 | 5652 | 541 | def dfs(v): # vを訪問する
global time
seen[v] = 1
start[v] = time
time += 1
for next_v in graph[v]:
if seen[next_v]: continue
dfs(next_v)
end[v] = time
time += 1
n = int(input())
graph = []
for _ in range(n):
line = list(map(int, input().split()))
graph.append([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,134 |
s885786164 | p02238 | u450519077 | 1591533995 | Python | Python3 | py | Accepted | 20 | 5636 | 456 | import sys
n = int(input())
G = [None]*(n+1)
for i in range(n):
u, k, *vs = map(int, input().split())
G[u] = vs
d = [-1]*(n+1)
f = [-1]*(n+1)
lb = iter(range(1, 2*n+1)).__next__
def dfs(v):
d[v] = lb()
for w in G[v]:
if d[w] != -1: #already visited
continue
dfs(w)
f[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,135 |
s256920534 | p02238 | u798363880 | 1591447948 | Python | Python3 | py | Accepted | 20 | 6032 | 583 | from collections import deque
N=int(input())
color=["w"]*(N+1)
start=[None]*(N+1)
finish=[0]*(N+1)
rinsetu=[[] for i in range(N+1)]
for i in range(1,N+1):
a=list(map(int,input().split()))
a=a[2:]
rinsetu[i]=a
def dfs(i,t):
if color[i]=="w":
t+=1
start[i]=t
color[i]="g"
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,136 |
s957158107 | p02238 | u941938943 | 1591340415 | Python | Python3 | py | Accepted | 20 | 5652 | 636 | n = int(input())
G = [[] for _ in range(n)]
for _ in range(n):
u, k, *v = map(int, input().split())
u -= 1
G[u].extend(v)
seen = [False] * n
d = [-1] * n
f = [-1] * n
t = 1
def dfs(v):
global t
# print(v+1, t)
d[v] = t
t += 1
seen[v] = True
for next_v in G[v]:
next_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,137 |
s860546082 | p02238 | u502283627 | 1591280111 | Python | Python3 | py | Accepted | 30 | 5636 | 568 | import sys
sys.setrecursionlimit(3000)
n = int(input())
X = []
for _ in range(n):
x = list(map(int, input().split()))
if x[1] != 0:
X.append(x[2:])
else:
X.append([])
df = [[0, 0] for _ in range(n)]
t = 0
def search(i = 0):
global t
if df[i][0] == 0:
t += 1
df[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,138 |
s202333174 | p02238 | u208184442 | 1591104616 | Python | Python3 | py | Accepted | 30 | 6068 | 877 | import sys
sys.setrecursionlimit(10**9)
from collections import deque
n = int(input())
u = [[] for i in range(n+1)] #隣接リスト
for i in range(n):
v = list(map(int, input().split()))
u[v[0]] = v[1:] #v = [次数, 頂点...]
d = [-1] * (n+1)
f = [-1] * (n+1)
visited = [False] * (n+1)
visited[0] = True
time = 1
#再帰
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,139 |
s146225080 | p02238 | u781474375 | 1590892267 | Python | Python3 | py | Accepted | 20 | 5664 | 762 | def dfs(v, time_, d, f, dp):
if d[v] == 0:
d[v] = time_
for i in range(len(dp[v])):
if d[dp[v][i]] == 0:
time_ = dfs(dp[v][i], time_ + 1, d, f, dp)
f[v] = time_ + 1
return time_ + 1
def main():
N = int(input())
dp = [[] 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,140 |
s360068368 | p02238 | u153034461 | 1590764889 | Python | Python3 | py | Accepted | 30 | 6384 | 741 | import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
time = 1
def dfs(node):
global time
if visited[node] != -1:
return
visited[node] = 0
d[node] = time
time += 1
for v in edge[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,141 |
s908996259 | p02238 | u367619546 | 1590664695 | Python | Python3 | py | Accepted | 20 | 5640 | 841 | # ALDS_11_B - 深さ優先探索
import sys
n = int(input())
e = [None] * n
for _ in range(n):
u, k, *v = map(int, sys.stdin.readline().strip().split())
e[u - 1] = [i - 1 for i in v]
S = [] # stack
time = 0
t_in = [0] * n
t_out = [0] * n
fp = [False] * n # foot print 訪問の記録
def dfs(u):
global time
S.append(... | 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,142 |
s661649166 | p02238 | u430457144 | 1590570864 | Python | Python3 | py | Accepted | 20 | 5664 | 517 | N = int(input())
nodes = [tuple(map(int, input().split(' '))) for _ in range(N)]
d = [-1 for _ in range(N + 1)]
f = [-1 for _ in range(N + 1)]
clock = 0
def dfs(node):
global clock
if d[node] == -1:
clock += 1
d[node] = clock
neighbors = sorted(nodes[node - 1][2:])
for neighbor in 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,143 |
s945578793 | p02238 | u061207034 | 1590565514 | Python | Python3 | py | Accepted | 20 | 5664 | 553 | def dfs(i):
global t
t += 1
D[i] = t
for e in es[i]:
if D[e] == 0:
dfs(e)
t += 1
F[i] = t
if __name__ == "__main__":
N = int(input())
es = [[] for _ in range(N+1)]
for _ in range(N):
ipts = [int(ipt) for ipt in input().split()]
if ipts[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,144 |
s606712266 | p02238 | u855675048 | 1590455931 | Python | Python3 | py | Accepted | 20 | 5652 | 1,004 | class Node:
def __init__(self, data):
self.data = data
self.neighbors = list()
self.find_time = 0
self.end_time = 0
N = int(input())
work_id = 0
nodes = list()
nodes.append(Node(0))
for _ in range(N):
tmp_list = list( map(int, input().split()) )
node = Node(tmp_list[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,145 |
s585573243 | p02238 | u420091741 | 1590034761 | Python | Python3 | py | Accepted | 20 | 5636 | 817 |
def dfs(node_id):
global current_time #書かないとローカル変数扱いされる
go_time[node_id] = current_time
current_time += 1
for next_node in G[node_id]:
if visited[next_node] == True:
continue
visited[next_node] = True
dfs(next_node)
back_time[node_id] = current_time
curren... | 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,146 |
s492481546 | p02238 | u789716290 | 1589978926 | Python | Python3 | py | Accepted | 20 | 5752 | 1,056 | N = int(input())
inf = 10 ** 6
graph = [[] for i in range(N)]
visited = [0 for i in range(N)]
time = [[inf,inf] for i in range(N)]
for i in range(N):
a = list(map(int,input().split()))
a = list(map(lambda x: x - 1,a))
k,n = a[0],a[1]
if n >= 0:
graph[k] = a[2:]
con = 0
def dfs(cur,par):
#print("v",visi... | 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,147 |
s767016889 | p02238 | u545131994 | 1589902904 | Python | Python3 | py | Accepted | 30 | 6184 | 1,520 | from collections import deque
seen=[]
first_order =[]
last_order = []
def dfs(g, v, first_ptr, last_ptr):
first_ptr=first_ptr+1
last_ptr=first_ptr
first_order[v] = first_ptr
seen[v]=True
for next_v in g[v]:
if seen[next_v]:
continue
first_ptr, last_ptr=dfs(g, 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,148 |
s433509049 | p02238 | u870171689 | 1589896277 | Python | Python3 | py | Accepted | 40 | 6692 | 868 | #!/usr/bin/env python3
from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float('inf')
n_nodes = int(input())
graph = [[] for _ in range(n_nodes)]
for _ in range(n_nodes):
line = list... | 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,149 |
s150441820 | p02238 | u560996731 | 1589895425 | Python | Python3 | py | Accepted | 20 | 5672 | 768 | n = int(input())
g = [[] for _ in range(n+1)] #1-index
for i in range(n):
u, k, *v = map(int, input().split())
for j in v:
g[u].append(j)
#-------------------------------------------
def dfs(v): #未訪問の点vから潜っていく
global time
seen[v] = 1 #訪問済にする
time += 1
d[v] = time
if g[v]:
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,150 |
s953181813 | p02238 | u496924602 | 1589809262 | Python | Python3 | py | Accepted | 20 | 6104 | 549 | from collections import Counter
import sys
def input():
return sys.stdin.readline().strip()
def dfs(v):
start[v] = lb()
for w in g[v]:
if start[w] != None:
continue
dfs(w)
end[v] = lb()
n = int(input())
g = [None] * (n+1)
start = [None] * (n+1)
end = [None] * (n+1)
lb = it... | 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,151 |
s532072699 | p02238 | u124936061 | 1589748654 | Python | Python3 | py | Accepted | 30 | 5664 | 947 | #Boost Force / Backtracking
import sys
input = sys.stdin.readline
d = []
f = []
time = 0
#ทำการ search
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()) #รับค่าจำนวน... | 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,152 |
s735968548 | p02238 | u286314212 | 1589682414 | Python | Python3 | py | Accepted | 30 | 6096 | 1,013 | import collections,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
n = I()
ukv = [LI() for _ in range(n)]
graph = {i:collections.deque() for i in range(1,n+1)} #1_indexed
for x in ukv:
u,k,*v = x
for y in v:
graph[u].append(y)
... | 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,153 |
s171343836 | p02238 | u356546564 | 1589643017 | Python | Python3 | py | Accepted | 20 | 5656 | 517 | def dfs(v):
global t, d, f, visited
d[v] = t
visited[v] = True
t += 1
for u in AL[v]:
if not visited[u]:
dfs(u)
f[v] = t
t += 1
# 入力
n = int(input())
AL = [[] for _ in range(n + 1)]
for v in range(1, n + 1):
AL[v] = [int(x) for x in input().split()][2:]
# 計算
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,154 |
s302400579 | p02238 | u235534975 | 1589604523 | Python | Python3 | py | Accepted | 20 | 5632 | 783 | 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)
seen = [0]*n
to_do = []
in_list = [0]*n
out_list = [0]*n
count = 0
def dfs(v):
#print(v)
global count
if seen[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,155 |
s529578935 | p02238 | u678457820 | 1589544231 | Python | Python3 | py | Accepted | 20 | 5712 | 524 | def dfs(num, lst, d, f, cnt):
if d[num] != 0:
return cnt - 1
d[num] = cnt
for n in lst[num]:
cnt += 1
cnt = dfs(n - 1, lst, d, f ,cnt)
cnt += 1
f[num] = cnt
return cnt
n = int(input())
d = [0 for i in range(n)]
f = [0 for i in range(n)]
lst = []
for _ in range(n):
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,156 |
s108973722 | p02238 | u590535211 | 1589386962 | Python | Python3 | py | Accepted | 30 | 6052 | 1,003 | from collections import deque
q = deque()
n = int(input())
C = [deque() for _ in range(n+1)]
for i in range(n):
tmp = list(map(int,input().split()))
for j in range(tmp[1]):
C[tmp[0]].append(tmp[2+j])
visited = [False]*(n+1)
d = [0]*(n+1)
f = [0]*(n+1)
t = 0
def stack(i):
global t
if 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,157 |
s429958381 | p02238 | u906360845 | 1589374314 | Python | Python3 | py | Accepted | 20 | 5720 | 706 | cin = open(0).read().strip().split('\n')
n = int(cin[0])
g = [list(map(lambda x: int(x)-1, a.split(' ')[2:])) for a in cin[1:]]
first_order = [-1] * n
last_order = [-1] * n
ptr = 1
def dfs(g, seen, idx):
global first_order, first_order, ptr
first_order[idx] = ptr
ptr += 1
seen[idx] = True
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,158 |
s913177892 | p02238 | u428671978 | 1589193488 | Python | Python3 | py | Accepted | 30 | 5672 | 563 | from sys import stdin
readline=stdin.readline
#入力
n=int(readline())
m=n+1
u,k,v=[0]*m,[0]*m,[0]*m
for i in range(1,m):
u[i],k[i],*v[i]=map(int,readline().split())
d=[0]*m
f=[0]*m
flags=[False]*m
t=0
def dfs(now):
global t
t+=1
d[now]=t
flags[now]=True
for nex in v[now]:
if flags[nex]==... | 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,159 |
s884216591 | p02238 | u330854367 | 1589127674 | Python | Python3 | py | Accepted | 30 | 6092 | 1,013 | import collections,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
n = I()
ukv = [LI() for _ in range(n)]
graph = {i:collections.deque() for i in range(1,n+1)} #1_indexed
for x in ukv:
u,k,*v = x
for y in v:
graph[u].append(y)
... | 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,160 |
s330924036 | p02238 | u777962369 | 1589027337 | Python | Python3 | py | Accepted | 20 | 5644 | 788 | N = int(input())
edge = [[0] for _ in range(N)]
for i in range(N):
A = list(map(int, input().split()))
for i,a in enumerate(A):
A[i] -= 1
edge[A[0]] = sorted(A[2:])
ans = [[0,0] for _ in range(N)]
import sys
sys.setrecursionlimit(10**8)
def dfs(v,now):
if len(edge[v])>0:
for u in edge[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,161 |
s971700675 | p02238 | u893763407 | 1588920786 | Python | Python3 | py | Accepted | 20 | 5716 | 537 | def dfs(i, cnt):
D[i] = cnt
cnt += 1
for c in v[i]:
if D[c-1] == -1:
cnt = dfs(c-1, cnt)
F[i] = cnt
cnt += 1
return cnt
N = int(input())
g = [0]*N
k = [0]*N
v = [[] for _ in range(N)]
for i in range(N):
tmp = list(map(int, input().split()))
g[i] = tmp[0]
k[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,162 |
s418794059 | p02238 | u076235767 | 1588866880 | Python | Python3 | py | Accepted | 20 | 5672 | 618 | # -*- coding: utf-8 -*-
"""
Created on Thu May 7 23:19:34 2020
@author: Kanaru Sato
"""
def dfs(v):
global t
d[v] = t
t += 1
if conlist[v]:
for connectedv in conlist[v]:
if d[connectedv] == -1:
dfs(connectedv)
f[v] = t
t += 1
n = int(input())
conlist = [[] ... | 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,163 |
s200075510 | p02238 | u822971508 | 1588749815 | Python | Python3 | py | Accepted | 20 | 6108 | 1,062 | # -*- coding:utf-8 -*-
def solve():
from collections import deque
N = int(input())
Us = [[] for _ in range(N)]
for i in range(N):
_in = list(map(int, input().split()))
if len(_in) == 2:
continue
u, k, Vs = _in[0], _in[1], _in[2:]
Vs.sort()
for v in ... | 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,164 |
s302877806 | p02238 | u737337423 | 1588669025 | Python | Python3 | py | Accepted | 20 | 5720 | 590 | # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B&lang=ja
import sys
input = sys.stdin.readline
N = int(input())
G = [[a-1 for a in list(map(int, input().split()))[2:]] for _ in [0]*N]
visited = [0]*N
history = [[] for _ in [0]*N]
k = 0
def dfs(v=0, p=-1):
global k
visited[v] = 1
k +... | 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,165 |
s369794173 | p02238 | u596318921 | 1588575236 | Python | Python3 | py | Accepted | 20 | 5668 | 572 | n = int(input())
g = [[]for i in range(n)]
for i in range(n):
v = list(map(int,input().split()))
u = v[0]-1
k = v[1]
for j in range(k):
g[u].append(v[j+2]-1)
time = 1
ans = []
d = [0]*n
f = [0] *n
visited = [0]*n
def dfs(now,last = -1):
global time
visited[now] = 1
d[now] = 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,166 |
s797052214 | p02238 | u083949342 | 1588571838 | Python | Python3 | py | Accepted | 20 | 5668 | 981 | def dfs(vum,v,d,f,t):
# print('first')
# print(vum,v,d,f,t)
if f[v] >= 0:
return d,f,t
t += 1
d[v] = t
for u in vum[v]:
# print(v, d[v], f[v], u, d[u], f[u])
if d[u] >= 0:
# print('skip', str(v), str(u))
continue
d,f,t = dfs(vum,u,d,f,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,167 |
s312363610 | p02238 | u555063680 | 1588332997 | Python | Python3 | py | Accepted | 20 | 5716 | 531 | N = int(input())
edge = [[] for _ in range(N+1)]
d = [0] * (N+1)
f = [0] * (N+1)
for i in range(N):
t = list(map(int, input().split()))
for j in range(t[1]):
edge[t[0]].append(t[j+2])
#print(1)
def dfs(v, t):
if d[v] == 0:
d[v] = t
t += 1
else:
return t
for nv in edg... | 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,168 |
s993790484 | p02238 | u697569920 | 1588324402 | Python | Python3 | py | Accepted | 20 | 6084 | 1,276 | # 深さ優先探索(行きがけ、帰りがけ)
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,169 |
s020446403 | p02238 | u486183171 | 1588304165 | Python | Python3 | py | Accepted | 20 | 5800 | 554 | N = int(input())
G = [[0] * N for _ in range(N)]
time = 0
times = [{'s': 0, 'f': 0} for _ in range(N)]
for _ in range(N):
u, n, *K = map(int, input().split())
for k in K:
G[u - 1][k - 1] = 1
def dfs(u):
global time
time += 1
times[u]['s'] = time
for i in range(N):
if G[u][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,170 |
s192400152 | p02238 | u481381669 | 1588251778 | Python | Python3 | py | Accepted | 30 | 6088 | 873 | from collections import deque
n = int(input())
g = [deque([]) *n for _ in range(n)]
for i in range(n):
u, k, *V = list(map(int, input().split()))
V.sort()
for v in V:
g[u-1].append(v-1)
# g[v-1].append(u-1)
time = 0
arrive_time = [-1] * n
finish_time = [-1] * n
def dfs(v):
global 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,171 |
s975354978 | p02238 | u720435112 | 1588161025 | Python | Python3 | py | Accepted | 20 | 5744 | 689 | n = int(input())
M = [[0]*n for _ in range(n)]
for _ in range(n):
u, k, *V = map(int, input().split())
if k == 0:
continue
else:
for v in V:
M[u-1][v-1] = 1
color = ['White']*n
time = 0
d = [0]*n
f = [0]*n
def dfs_visit(u=0):
global time
color[u] = 'Gray'
time += 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,172 |
s033421168 | p02238 | u980837785 | 1588078907 | Python | Python3 | py | Accepted | 20 | 5652 | 461 | import sys
sys.setrecursionlimit(10 ** 9)
N = int(input())
graph = list()
for i in range(N):
x = list(map(int, input().split()))
graph.append(x[2:])
start = [0] * N
end = [0] * N
visited = [False] * N
time = 0
def dfs(n):
if visited[n]:
return
visited[n] = True
global time
time += 1
start[n] = 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,173 |
s889821722 | p02238 | u222010246 | 1587999920 | Python | Python3 | py | Accepted | 20 | 5656 | 573 | n = int(input())
trees = [[]]
for i in range(n):
edges = []
s = list(map(int, input().split()))
num = s[1]
if s[1] != 0:
edges = s[2:2+num]
trees.append(edges)
d = [0] * (n+1)
f = [0] * (n+1)
def dfs(x, i=0):
for y in trees[x]:
if d[y] != 0:
continue
d[y] =... | 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,174 |
s130263234 | p02238 | u697273228 | 1587926201 | Python | Python3 | py | Accepted | 30 | 6092 | 851 | n = int(input())
from collections import deque
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)
arrive = [-1 for i in range(n+1)]
finish = [-1 for i in range(n+1)]
times = 0
def dfs(v):
glob... | 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,175 |
s817426707 | p02238 | u157179698 | 1587900832 | Python | Python3 | py | Accepted | 20 | 5732 | 956 | from sys import stdin
input = stdin.readline
N = int(input())
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 += 1
d[u] = tt # 最初の訪問
for v in range(N):
if M[u][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,176 |
s449730964 | p02238 | u475213171 | 1587892337 | Python | Python3 | py | Accepted | 20 | 5640 | 743 | import sys
sys.setrecursionlimit(10000000)
n = int(input())
G = [[] for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
color = [0 for i in range(n)]
stamp = 0
def dfs(u):
global stamp
if d[u]:
return
stamp += 1
d[u] = stamp
for v in G[u]:
if color[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,177 |
s545553799 | p02238 | u583793648 | 1587709291 | Python | Python3 | py | Accepted | 20 | 5664 | 396 | n = int(input())
g = [[] for i in range(n)]
for i in range(n):
g[i] = list(map(lambda x:int(x)-1,input().split()))[2:]
def dfs(v,t):
t += 1
d[v] = t
for i in g[v]:
if d[i]==-1:
t = dfs(i,t)
t += 1
f[v] = t
return t
t = 0
d = [-1]*n
f = [-1]*n
for i in range(n):
if ... | 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,178 |
s649556507 | p02238 | u382571188 | 1587480528 | Python | Python3 | py | Accepted | 20 | 5800 | 872 | N = 100
WHITE = 0
GRAY = 1
BLACK = 2
d = [-1] * N
f = [-1] * N
def dfs_visit(n, u, tt, color):
global d
global f
color[u] = GRAY
tt += 1
d[u] = tt
for v in range(n):
if M[u][v] == 0:
continue
if color[v] == WHITE:
tt = dfs_visit(n, v, tt, color)
colo... | 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,179 |
s387010074 | p02238 | u647694976 | 1587347918 | Python | Python3 | py | Accepted | 30 | 5712 | 526 | def DFS(num):
global time
time +=1
color[num]="gray"
D[num][0]=time
for i in M[num]:
if color[i]=="white":
DFS(i)
color[num]="black"
time +=1
D[num][1]=time
n=int(input())
M=[[] for _ in range(n+1)]
for i in range(n):
for j in list(map(int,input().split()))[2:]:... | 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,180 |
s856321151 | p02238 | u909811933 | 1587269335 | Python | Python3 | py | Accepted | 20 | 5664 | 506 | import sys
sys.setrecursionlimit(10**7)
time = 0
def input():
return sys.stdin.readline()
n = int(input())
G = [[]]
d = [0]*(n+1)
f = [0]*(n+1)
for _ in range(n):
G.append(list(map(int,input().split()))[2:])
def dfs(e):
global time
d[e] = time
for nexte in G[e]:
if d[nexte] == 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,181 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.