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
s530767450
p02238
u022407960
1479669695
Python
Python3
py
Accepted
30
7880
2,457
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 def generate_adj_matrix(v_info): for v_detail in v_info: v_adj_list = v_detail[2:] # assert len(v_adj_list) == int(v_detail[1]) for each in v_adj_list: init_adj_matrix[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
28,982
s719468387
p02238
u022407960
1479890763
Python
Python3
py
Accepted
50
8164
2,014
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 1 2 2 3 2 2 3 4 3 1 5 4 1 6 5 1 6 6 0 output: 1 1 12 2 2 11 3 3 8 4 9 10 5 4 7 6 5 6 """ import sys from collections import deque UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 def generate_adj_matrix(v_info): for v_detail in v_info: v_index...
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
28,983
s749121414
p02238
u022407960
1479890792
Python
Python3
py
Accepted
30
8176
2,014
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 1 2 2 3 2 2 3 4 3 1 5 4 1 6 5 1 6 6 0 output: 1 1 12 2 2 11 3 3 8 4 9 10 5 4 7 6 5 6 """ import sys from collections import deque UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 def generate_adj_matrix(v_info): for v_detail in v_info: v_index...
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
28,984
s232170703
p02238
u022407960
1479891272
Python
Python3
py
Accepted
30
7812
1,989
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 1 2 2 3 2 2 3 4 3 1 5 4 1 6 5 1 6 6 0 output: 1 1 12 2 2 11 3 3 8 4 9 10 5 4 7 6 5 6 """ import sys UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 def generate_adj_matrix(v_info): for v_detail in v_info: v_index, adj_num, *adj_list = 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
28,985
s174298811
p02238
u022407960
1479892460
Python
Python3
py
Accepted
20
7796
2,052
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 1 2 2 3 2 2 3 4 3 1 5 4 1 6 5 1 6 6 0 output: 1 1 12 2 2 11 3 3 8 4 9 10 5 4 7 6 5 6 """ import sys UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 def generate_adj_matrix(v_info): for v_detail in v_info: v_index, adj_num, *adj_list = 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
28,986
s023915278
p02238
u022407960
1480331758
Python
Python3
py
Accepted
30
7784
2,058
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 1 2 2 3 2 2 3 4 3 1 5 4 1 6 5 1 6 6 0 output: 1 1 12 2 2 11 3 3 8 4 9 10 5 4 7 6 5 6 """ import sys UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 def generate_adj_matrix(v_info): for v_detail in v_info: v_index, adj_num, *adj_list = 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
28,987
s843964990
p02238
u022407960
1480331931
Python
Python3
py
Accepted
30
7796
2,021
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 1 2 2 3 2 2 3 4 3 1 5 4 1 6 5 1 6 6 0 output: 1 1 12 2 2 11 3 3 8 4 9 10 5 4 7 6 5 6 """ import sys UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 def generate_adj_matrix(v_info): for v_detail in v_info: v_index, adj_num, *adj_list = 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
28,988
s765492618
p02238
u159356473
1481012380
Python
Python3
py
Accepted
20
7760
487
#coding:utf-8 def DFS(i,A,d,f,t): if d[i-1]: return t d[i-1]=t t+=1 for j in A[i-1]: t=DFS(j,A,d,f,t) f[i-1]=t t+=1 return t if __name__=="__main__": n=int(input()) A=[] for i in range(n): A.append(list(map(int,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
28,989
s637813768
p02238
u811733736
1481082722
Python
Python3
py
Accepted
40
8176
2,372
from enum import Enum class Dfs(object): """ Depth First Search """ class Status(Enum): white = 1 gray = 2 black = 3 def __init__(self, data): self.time = 0 num_of_nodes = len(data)+1 self.color = [Dfs.Status.white] * (num_of_nodes+1) self.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
28,990
s414876741
p02238
u022407960
1481627083
Python
Python3
py
Accepted
20
7812
1,852
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 1 2 2 3 2 2 3 4 3 1 5 4 1 6 5 1 6 6 0 output: 1 1 12 2 2 11 3 3 8 4 9 10 5 4 7 6 5 6 """ import sys UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 def dfs(v_init): global timer # init the first node of overall graph iterations(times >= 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
28,991
s434509123
p02238
u022407960
1481627220
Python
Python3
py
Accepted
20
7768
1,852
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 1 2 2 3 2 2 3 4 3 1 5 4 1 6 5 1 6 6 0 output: 1 1 12 2 2 11 3 3 8 4 9 10 5 4 7 6 5 6 """ import sys UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 def dfs(v_init): global timer # init the first node of overall graph iterations(times >= 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
28,992
s607928052
p02238
u022407960
1481627256
Python
Python3
py
Accepted
20
7788
1,852
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 1 2 2 3 2 2 3 4 3 1 5 4 1 6 5 1 6 6 0 output: 1 1 12 2 2 11 3 3 8 4 9 10 5 4 7 6 5 6 """ import sys UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 def dfs(v_init): global timer # init the first node of overall graph iterations(times >= 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
28,993
s457945912
p02238
u022407960
1481627599
Python
Python3
py
Accepted
20
7776
1,771
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 1 2 2 3 2 2 3 4 3 1 5 4 1 6 5 1 6 6 0 output: 1 1 12 2 2 11 3 3 8 4 9 10 5 4 7 6 5 6 """ import sys UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 def dfs(v_init): global timer # init the first node of overall graph iterations(times >= 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
28,994
s677210436
p02238
u564398841
1485189313
Python
Python3
py
Accepted
20
7876
1,466
def dfs(u, colors, matrix, time, detect_time, finished_time): # ????????????????????¨?????????????????? colors = colors detect_time = detect_time finished_time = finished_time time = time + 1 stack = list() stack.append(u) colors[u] = 1 detect_time[u] = time while len(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
28,995
s574399946
p02238
u923668099
1486101118
Python
Python3
py
Accepted
20
7824
1,037
import sys def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None time = 0 def dfs(u, adj, d, f, sumi): global time sumi.add(u) time += 1 d[u] = time for v in adj[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
28,996
s969423393
p02238
u112247126
1488335298
Python
Python3
py
Accepted
30
7784
711
def dfs_recursive(u): global time color[u] = 'gray' arrive[u] = time time += 1 for v in range(n): if adjMat[u][v] == 1 and color[v] == 'white': dfs_recursive(v) color[u] = 'black' finish[u] = time time += 1 n = int(input()) adjMat = [[0] * n for _ in range(n)] 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
28,997
s067732905
p02238
u089830331
1495494278
Python
Python3
py
Accepted
30
7732
886
def get_unvisted_child(v, timestamp): while len(G[v]) > 0: c = G[v].pop(0) if not c in timestamp: return c return -1 def get_unvisited_node(G, timestamp): for v in sorted(G): if not v in timestamp: return v return -1 def dept_first_search(G): t = 1 timestamp = {} stack = [] v = get_unvisi...
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
28,998
s194400047
p02238
u603049633
1496487444
Python
Python3
py
Accepted
20
7700
632
n = int(input()) Adj = [[0 for i in range(n)] for i in range(n)] for i in range(n): u = list(map(int, input().split())) if u[1] > 0: for i in u[2: 2 + u[1]]: Adj[u[0] - 1][i - 1] = 1 color = [0] * n d = [0] * n f = [0] * n time = 0 def dfs(u): global time color[u - 1] = 1 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
28,999
s287692383
p02238
u371539389
1497098839
Python
Python3
py
Accepted
20
7820
884
n=int(input()) #V[u]=[k,[v],d,f] V=[[0,[],0,0]] for i in range(n): v=[int(i) for i in input().split(" ")] u=v.pop(0) k=v.pop(0) v.sort() V.append([k,v,0,0]) def is_finished(Id): k=V[Id][0] v=V[Id][1] for i in range(k): if V[v[i]][2]==0: return v[i] return -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,000
s361185569
p02238
u067677727
1498884057
Python
Python3
py
Accepted
20
7944
1,559
def DFS(adj, start): n = len(adj) d = [0] * n f = [0] * n flag = [0] * n S = [] time = 1 S.append(start) flag[start] = 1 d[start] = time time = time + 1 while flag.count(2) != n: # ??¨????????????????????¢?´¢????????????????????§ if len(S) != 0: 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,001
s772485720
p02238
u067677727
1498884116
Python
Python3
py
Accepted
20
7888
1,584
# -*- coding: utf-8 -*- def DFS(adj, start): n = len(adj) d = [0] * n f = [0] * n flag = [0] * n S = [] time = 1 S.append(start) flag[start] = 1 d[start] = time time = time + 1 while flag.count(2) != n: # ??¨????????????????????¢?´¢????????????????????§ if len(...
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,002
s467258916
p02238
u067677727
1498884359
Python
Python3
py
Accepted
20
7924
1,438
# -*- coding: utf-8 -*- def DFS(adj, start): n = len(adj) d = [0] * n f = [0] * n flag = [0] * n S = [] time = 1 S.append(start) flag[start] = 1 d[start] = time time = time + 1 while flag.count(2) != n: # ??¨????????????????????¢?´¢????????????????????§ if len(...
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,003
s110551480
p02238
u426534722
1499443751
Python
Python3
py
Accepted
20
7768
451
from sys import stdin n = int(stdin.readline()) M = [0] + [list(map(int, stdin.readline().split()[2:])) for i in range(n)] sndf = [0] + [[False, i] for i in range(1, n + 1)] tt = 0 def dfs(u): global tt sndf[u][0] = True tt += 1 sndf[u].append(tt) for v in M[u]: if not sndf[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,004
s444467207
p02238
u426534722
1499443993
Python
Python3
py
Accepted
20
7784
457
from sys import stdin n = int(stdin.readline()) M = [None] + [list(map(int, stdin.readline().split()[2:])) for i in range(n)] sndf = [None] + [[False, i] for i in range(1, n + 1)] tt = 0 def dfs(u): global tt sndf[u][0] = True tt += 1 sndf[u].append(tt) for v in M[u]: if not sndf[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,005
s056341113
p02238
u426534722
1499444124
Python
Python3
py
Accepted
30
7728
466
from sys import stdin n = int(stdin.readline()) M = [None] M += [list(map(int, stdin.readline().split()[2:])) for i in range(n)] sndf = [None] sndf += [[False, i] for i in range(1, n + 1)] tt = 0 def dfs(u): global tt sndf[u][0] = True tt += 1 sndf[u].append(tt) for v in M[u]: if not sndf[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,006
s265807929
p02238
u426534722
1499444615
Python
Python3
py
Accepted
30
7792
479
from sys import stdin n = int(stdin.readline()) M = [None] M += [list(map(int, stdin.readline().split()[2:])) for i in range(n)] sndf = [None] sndf += [[False, i] for i in range(1, n + 1)] tt = 0 def dfs(u): global tt sndf[u][0] = True tt += 1 sndf[u].append(tt) for v in M[u]: if not sndf[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,007
s210645852
p02238
u426534722
1499444655
Python
Python3
py
Accepted
20
7788
470
from sys import stdin n = int(stdin.readline()) M = [None] + [list(map(int, stdin.readline().split()[2:])) for i in range(n)] sndf = [None] + [[False, i] for i in range(1, n + 1)] tt = 0 def dfs(u): global tt sndf[u][0] = True tt += 1 sndf[u].append(tt) for v in M[u]: if not sndf[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,008
s383372197
p02238
u426534722
1499445092
Python
Python3
py
Accepted
30
7840
450
from sys import stdin n = int(stdin.readline()) M = [list(map(int, stdin.readline().split()[2:])) for i in range(n)] sndf = [[False, i] for i in range(1, n + 1)] tt = 0 def dfs(u): global tt sndf[u][0] = True tt += 1 sndf[u].append(tt) for v in M[u]: v -= 1 if not sndf[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,009
s926694740
p02238
u067677727
1499737598
Python
Python3
py
Accepted
20
7936
2,273
# -*- coding: utf-8 -*- def DFS_stack(adj, start): n = len(adj) d = [0] * n f = [0] * n flag = [0] * n # 0:????¨????, 1:?¨??????????, 2:?¨?????????? S = [] time = 1 S.append(start) flag[start] = 1 d[start] = time time = time + 1 while flag.count(2) != 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,010
s377694465
p02238
u091533407
1500415030
Python
Python3
py
Accepted
30
7912
661
import sys def dfs(u): global time color[u] = "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 if __name__ == "__main__": n = int(sys.stdin.readline()) color = ["WHITE"] * 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,011
s735292327
p02238
u539803218
1500451233
Python
Python3
py
Accepted
30
7748
542
# coding: utf-8 def depth(i, adj, Dep, Arr, times): if Dep[i-1]: return times Dep[i-1]=times times+=1 # t=[depth(j, adj, Dep, f, times) j in adj[i-1]] for j in adj[i-1]: times=depth(j, adj, Dep, Arr, times) Arr[i - 1]=times times+=1 return times n=int(input()) adj=[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,012
s960149552
p02238
u278938795
1500615504
Python
Python3
py
Accepted
30
7760
667
import sys #sys.setrecursionlimit(100000) u=[] k=[] v=[] time = 0 n=int(sys.stdin.readline().strip()) yattayatu=[False for i in range(n)] s=[0 for i in range(n)] f=[0 for i in range(n)] for i in range(n): inp = sys.stdin.readline().strip().split(" ") inp = list(map(lambda x: int(x), inp)) u.append(inp[0]) k.ap...
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,013
s199609661
p02238
u735204496
1500615598
Python
Python
py
Accepted
10
6456
1,109
import sys d_num = int(sys.stdin.readline().strip()) graph_list = [] for _ in range(0, d_num): array = sys.stdin.readline().strip().split(" ") if len(array) <= 2: graph_list.append([]) else: graph_list.append([int(array[i]) - 1 for i in range(2, len(array))]) t = 1 result = [[] for _ 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,014
s573931392
p02238
u858885710
1500626397
Python
Python3
py
Accepted
30
7768
666
from sys import stdin d_num = int(stdin.readline().strip()) graph = [[] for _ in range(d_num+1)] for _ in range(d_num): u, k, *neighbors = map(int, stdin.readline().split()) for v in neighbors: graph[u].append(v) visited = set() timestamps = [None for _ in range(d_num+1)] def dfs(u, stmp): visit...
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,015
s189335521
p02238
u491916705
1502764937
Python
Python
py
Accepted
10
6900
1,894
from collections import OrderedDict class Stack(): def __init__(self): self.el = [] def add(self, el): self.el.append(el) def pop(self): return self.el.pop() def top(self): return self.el[-1] def isEmpty(self): if self.el: return False ret...
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,016
s253568536
p02238
u510829608
1502860696
Python
Python3
py
Accepted
20
7828
729
N = int(input()) Adj = [[0 for i in range(N)] for j in range(N)] for i in range(N): u = list(map(int, input().split())) if u[1] > 0: for k in u[2: 2+u[1]]: Adj[u[0] - 1][k - 1] = 1 color = [0] * N #1: visited, 0: not visited, 2: completed s = [0] * N # start f = [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,017
s581546860
p02238
u855199458
1502977637
Python
Python3
py
Accepted
20
7832
951
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(100000) N = int(input()) adj = [[0]*N for _ in range(N)] searched = {n: 0 for n in range(N)} edge = {} for n in range(N): inp = list(map(int, input().split())) edge[n] = inp[1] for i in inp[2:]: adj[inp[0]-1][i-1] = 1 time = 1 stack = [] uns...
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,018
s402153526
p02238
u519227872
1504185059
Python
Python3
py
Accepted
20
7800
1,132
n = int(input()) graph = {} ans = [] np = set(range(1,n+1)) for i in range(n): t = list(map(int, input().split())) v = t[0] k = t[1] graph[v] = [t[i+2] for i in range(k)] np=np - set(graph[v]) ans.append([v,None,None]) class Time: def __init__(self): self.time = 0 def getTime(se...
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,019
s443329337
p02238
u193453446
1504768743
Python
Python3
py
Accepted
20
7808
1,027
def srch(u, cnt, Dst, Fst, Lst): S = [u] Fst[u] = cnt while(len(S) > 0): cnt += 1 u = S.pop() if Dst[u] is not None and len(Dst[u]) > 0: while(len(Dst[u])): u1 = Dst[u].pop() if Fst[u1] == 0: S.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,020
s386853379
p02238
u659034691
1504950061
Python
Python3
py
Accepted
50
7916
933
#depth first N=int(input()) V=[] a=[0] for i in range(N): V.append([int(i) for i in input().split()]) w=V[i][2:] w.sort() V[i]=V[i][:2]+w a.append(0) V=sorted(V,key=lambda x:x[0]) c=1 t=1 i=0 r=[1] a[1]=1 p=[[1,t]] q=[] while t<N*2: j=2 while t<N*2 and j-2<V[i][1] and V[i][1]>0 and a[V[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,021
s783611717
p02238
u810434660
1505305902
Python
Python3
py
Accepted
20
7840
1,659
# coding: utf-8 timestamp = 1 stack = [] indata = [] visit = [] #?¨?????¨???? visitTime = [] #?¨???????????¨??????¨ lastTimeStack = [] #?¨?????????????????¨??????¨ def inputdata(): global visit global indata global visitTime n = int(input().rstrip()) 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,022
s337912919
p02238
u796784914
1505543956
Python
Python
py
Accepted
10
6496
622
def main(): n = input() A = [] s = [] B = [[0,0] for i in xrange(n)] for i in xrange(n): A.append(map(int,raw_input().split())) color = [-1]*n d = [0]*n f = [0]*n t = 0 for i in xrange(n): if color[i] == -1: t = dfs(i,t,color,d,f,A,n) 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,023
s181767555
p02238
u368364462
1505656962
Python
Python
py
Accepted
10
6432
1,012
N = input() color = [0] * N d = [0] * N f = [0] * N nt = [0] * N m = [[0] * N for i in range(N)] S = [] tt = 0 def next(u): global nt w = nt[u] for v in range(w, N): nt[u] = v + 1 if( m[u][v] ): return v return -1 def dfs_visit(r): global tt S.append(r) color[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,024
s585958504
p02238
u236679854
1506952359
Python
Python3
py
Accepted
20
7748
576
n = int(input()) G = [] checked = [False for i in range(n + 1)] d = [0 for i in range(n + 1)] f = [0 for i in range(n + 1)] G.append([]) for i in range(n): u, k, *v = map(int, input().split()) G.append(v) timestamp = 1 def dfs(id): global timestamp checked[id] = True d[id] = timestamp timesta...
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,025
s500093372
p02238
u792145349
1507347803
Python
Python3
py
Accepted
50
7832
814
n = int(input()) graph = [list(map(int, input().split())) for i in range(n)] v_color = ["WHITE"] * (n+1) # WHITE:????¨???????GRAY:?¨??????????BLACK:??¢?´¢?????? d = [0] * (n+1) f = [0] * (n+1) stack = [] time = 0 def DFS(u): global time stack.append(u) while stack != []: u = stack[-1] 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,026
s294754556
p02238
u756958775
1507397373
Python
Python3
py
Accepted
50
7852
741
n = int(input()) A = [[False for _ in range(n)] for _ in range(n)] for _ in range(n): tmp = list(map(int, input().split())) for i in range(tmp[1]): A[tmp[0]-1][tmp[i+2]-1] = True WHITE = 0 GRAY = 1 BLACK = 2 color = [WHITE for _ in range(n)] d = [0 for _ in range(n)] f = [0 for _ in range(n)] 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,027
s053228742
p02238
u798803522
1509548306
Python
Python3
py
Accepted
30
8144
701
from collections import defaultdict def dfs(here, connect, visited, answer): global time answer[here][1] = time time += 1 visited[here] = 1 for c in connect[here]: if not visited[c]: dfs(c, connect, visited, answer) answer[here][2] = time time += 1 v_num = 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,028
s417908155
p02238
u024715419
1510552905
Python
Python3
py
Accepted
20
7896
620
j = 1 def dfs(graph, start, result, visited=None): global j if visited == None: visited = [] visited.append(start) result[start][1] = j for next in graph[start][2:]: if next in visited: continue j += 1 dfs(graph, next, result, visited) 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,029
s370577174
p02238
u856963614
1511541637
Python
Python3
py
Accepted
50
7932
1,156
n=int(input()) adj=[] for i in range(n): adj.append(list(map(int, input().split()))) edge=[[0 for i2 in range(n)]for i1 in range(n)] #??£??\??????????????? for i in range(n): for j in range(adj[i][1]): edge[i][adj[i][j+2]-1]=1 time=1 discover=[0 for i in range(n)] final=[0 for i in range(n)] stac...
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,030
s611604389
p02238
u626266743
1511872300
Python
Python3
py
Accepted
20
5808
727
def dfs(u): global dfs_color, d, f, t color[u] = GRAY d[u] += t t += 1 for v in range(n): if (M[u][v] == 0): continue else: if (color[v] == WHITE): dfs(v) color[u] = BLACK f[u] = t t += 1 n = int(input()) M = [[False 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,031
s921083890
p02238
u424457654
1511884567
Python
Python3
py
Accepted
20
5808
729
def dfs_visit(u): global dfs_color, d, f, t color[u] = GRAY d[u] += t t += 1 for v in range(n): if M[u][v] == 0: continue if color[v] == WHITE: dfs_visit(v) color[u] = BLACK f[u] += t t += 1 n = int(input()) M = [[False for i in range(n)] for j 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,032
s510761537
p02238
u845643816
1511921309
Python
Python3
py
Accepted
20
5796
641
n = int(input()) a = [[0]*n for i in range(n)] for i in range(n): v = list(map(int, input().split())) u = v[0] k = v[1] for j in range(k): a[u - 1][v[2 + j] - 1] = 1 d = [0] * n f = [0] * n isDiscovered = [False] * n time_stamp = 0 def dfs(x): global time_stamp isDiscovered [x] = Tr...
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,033
s674626824
p02238
u845643816
1511921494
Python
Python3
py
Accepted
20
5796
632
n = int(input()) a = [[False]*n for i in range(n)] for i in range(n): v = list(map(int, input().split())) u = v[0] k = v[1] for j in range(k): a[u - 1][v[2 + j] - 1] = True d = [0] * n f = [0] * n isDiscovered = [False] * n time_stamp = 0 def dfs(x): global time_stamp isDiscovered [...
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,034
s755767518
p02238
u845643816
1512127178
Python
Python3
py
Accepted
20
5656
559
n = int(input()) a = [[] for i in range(n)] for i in range(n): v = list(map(int, input().split())) u = v[0] - 1 for j in v[2:]: a[u].append(j-1) d = [0] * n f = [0] * n isDiscovered = [False] * n time_stamp = 0 def dfs(x): global time_stamp isDiscovered [x] = True time_stamp += 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,035
s797444307
p02238
u185486509
1514703473
Python
Python3
py
Accepted
20
5660
475
n=int(input()) adj=[None] for i in range(n): adj_i=list(map(int,input().split()[2:])) adj.append(adj_i) sndf=[None] for i in range(1,n+1): sndf.append([False,i]) path=[] time=0 def dfs(u): global time sndf[u][0]=True time+=1 sndf[u].append(time) for v in adj[u]: if not sndf[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,036
s799686333
p02238
u672443148
1515302718
Python
Python3
py
Accepted
20
5628
536
n=int(input()) d=[0 for _ in range(n+1)] f=[0 for _ in range(n+1)] G=[] G.append([]) for i in range(n): u,k,*v=map(int,input().split()) G.append(v) checked=[False for _ in range(n+1)] timestamp=1 def dfs(id): global timestamp d[id]=timestamp checked[id]=True timestamp+=1 for v in G[id]: ...
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,037
s380201502
p02238
u650712316
1517659488
Python
Python3
py
Accepted
30
6072
1,054
# coding: UTF-8 from collections import deque #入力値の整理 n = int(input()) adj={} visited={} d={} f={} t=0 visited=set() for i in range(n): raw=list(map(int,input().split())) u = raw.pop(0) k = raw.pop(0) raw.sort() q = deque(raw) adj[u] = q d[u] = -1 f[u] = -1 next = 1 v = next d[next] = t + 1 stack = 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,038
s508187137
p02238
u650712316
1517745954
Python
Python3
py
Accepted
30
6088
780
# coding: UTF-8 from collections import deque n = int(input()) arrow = {} visited = set() d = {} f = {} for i in range(n): raw = list(map(int,input().split())) #print(raw) u = raw.pop(0) k = raw.pop(0) raw.sort() q = deque(raw) arrow[u] = q d[u] = -1 f[u] = -1 def dfslocal(v,t,arrow,f,d): t += 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,039
s866986064
p02238
u662418022
1517921315
Python
Python3
py
Accepted
20
5800
777
# -*- coding: utf-8 -*- if __name__ == '__main__': n = int(input()) M = [[0 for i in range(n)] for j in range(n)] for _ in range(n): l = list(map(int, input().split(" "))) u = l[0] k = l[1] if k != 0: for v in l[2:]: M[u-1][v-1] = 1 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,040
s349738748
p02238
u152085200
1518402283
Python
Python
py
Accepted
10
4756
1,358
from sys import stdin global time time = 0 def dfs(graph,start,state,discover,finish): state[start-1] = 1 global time time = time + 1 discover[start-1] = time # print str(time) + " go to " + str(start) neighbours = sorted(graph[start]) for neighbour in neighbours: if state[neigh...
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,041
s245896837
p02238
u426534722
1519051307
Python
Python3
py
Accepted
20
5628
597
def MAIN(): n = int(input()) ans = [[i, 0, 0] for i in range((n + 1))] G = [[] for _ in range((n + 1))] for _ in range(n): u, k, *v = map(int, input().split()) G[u] = v cnt = 1 def dfs(u): nonlocal ans if ans[u][1] != 0: return nonlocal cnt ...
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,042
s987648723
p02238
u426534722
1519051445
Python
Python3
py
Accepted
20
5720
578
def MAIN(): n = int(input()) ans = [[i, 0, 0] for i in range((n + 1))] G = [[] for _ in range((n + 1))] for _ in range(n): u, k, *v = map(int, input().split()) G[u] = v cnt = 1 def dfs(u): nonlocal ans if ans[u][1] != 0: return nonlocal cnt ...
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,043
s645654709
p02238
u426534722
1519051541
Python
Python3
py
Accepted
20
5656
548
def MAIN(): n = int(input()) ans = [[i, 0, 0] for i in range((n + 1))] G = [[] for _ in range((n + 1))] for _ in range(n): u, k, *v = map(int, input().split()) G[u] = v cnt = 1 def dfs(u): nonlocal ans if ans[u][1] != 0: return nonlocal cnt ...
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,044
s211779468
p02238
u150984829
1520027688
Python
Python3
py
Accepted
30
5792
339
def d(u): global t C[u]=1;t+=1;D[u]=t for v in range(N): if M[u][v]and C[v]==0:d(v) C[u]=2;t+=1;F[u]=t N=int(input()) M=[[0]*N for _ in[0]*N] for e in[list(map(int,input().split()))for _ in[0]*N]: for v in e[2:]:M[e[0]-1][v-1]=1 C,D,F=[0]*N,[0]*N,[0]*N t=0 for i in range(N): if C[i]==0:d(i) for i in range(N):pr...
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,045
s268581998
p02238
u150984829
1520027690
Python
Python3
py
Accepted
20
5788
339
def d(u): global t C[u]=1;t+=1;D[u]=t for v in range(N): if M[u][v]and C[v]==0:d(v) C[u]=2;t+=1;F[u]=t N=int(input()) M=[[0]*N for _ in[0]*N] for e in[list(map(int,input().split()))for _ in[0]*N]: for v in e[2:]:M[e[0]-1][v-1]=1 C,D,F=[0]*N,[0]*N,[0]*N t=0 for i in range(N): if C[i]==0:d(i) for i in range(N):pr...
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,046
s147233261
p02238
u150984829
1520027842
Python
Python3
py
Accepted
20
5800
334
def d(u): global t C[u]=1;t+=1;D[u]=t for v in range(N): if M[u][v]and C[v]==0:d(v) C[u]=2;t+=1;F[u]=t N=int(input()) M=[[0]*N for _ in[0]*N] for e in[input().split()for _ in[0]*N]: for v in e[2:]:M[int(e[0])-1][int(v)-1]=1 C,D,F=[0]*N,[0]*N,[0]*N t=0 for i in range(N): if C[i]==0:d(i) for i in range(N):print(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,047
s766404856
p02238
u150984829
1520028606
Python
Python3
py
Accepted
30
5792
305
def d(u): global t C[u]=0;t+=1;D[u]=t for v in R: if M[u][v]and C[v]:d(v) t+=1;F[u]=t N=int(input());R=range(N) M=[[0]*N for _ in R] for e in[input().split()for _ in R]: for v in e[2:]:M[int(e[0])-1][int(v)-1]=1 C,D,F=[1]*N,[0]*N,[0]*N t=0 for i in R: if C[i]:d(i) for i in R:print(i+1,D[i],F[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,048
s783398543
p02238
u150984829
1520028608
Python
Python3
py
Accepted
20
5796
305
def d(u): global t C[u]=0;t+=1;D[u]=t for v in R: if M[u][v]and C[v]:d(v) t+=1;F[u]=t N=int(input());R=range(N) M=[[0]*N for _ in R] for e in[input().split()for _ in R]: for v in e[2:]:M[int(e[0])-1][int(v)-1]=1 C,D,F=[1]*N,[0]*N,[0]*N t=0 for i in R: if C[i]:d(i) for i in R:print(i+1,D[i],F[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,049
s824781972
p02238
u150984829
1520029205
Python
Python3
py
Accepted
20
5720
243
def d(u): global t C[u]=0;D[u]=t;t+=1 for v in M[u]: v=int(v)-1 if C[v]:d(v) F[u]=t;t+=1 N=int(input());R=range(N) M=[input().split()[2:]for _ in R] C,D,F=[1]*N,[0]*N,[0]*N t=1 for i in R: if C[i]:d(i) for i in R:print(i+1,D[i],F[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,050
s049425709
p02238
u150984829
1520029395
Python
Python3
py
Accepted
20
5720
236
def d(u): global t C[u]=0;D[u]=t;t+=1 for v in M[u]:v=int(v)-1;C[v]and d(v) F[u]=t;t+=1 N=int(input());R=range(N) M=[input().split()[2:]for _ in R] C,D,F=[1]*N,[0]*N,[0]*N t=1 for i in R:C[i]and d(i) for i in R:print(i+1,D[i],F[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,051
s069870186
p02238
u150984829
1520029956
Python
Python3
py
Accepted
20
5712
234
def d(u): global t C[u]=1;D[u]=t;t+=1 for v in M[u]:v=int(v)-1;C[v]or d(v) F[u]=t;t+=1 N=int(input());R=range(N) M=[input().split()[2:]for _ in R] C,D,F=[0]*N,[0]*N,[0]*N t=1 for i in R:C[i]or d(i) for i in R:print(i+1,D[i],F[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,052
s658939185
p02238
u869924057
1520423856
Python
Python3
py
Accepted
20
5708
1,343
class Vertex: _id = -1 _children = [] _visited = False _visited_time = 0 _all_visited_time = 0 def __init__(self, i, c): self._id = i self._children = c def getId(self): return self._id def getChildren(self): return self._children def isVisited(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,053
s588114089
p02238
u126478680
1525502311
Python
Python3
py
Accepted
40
6488
1,166
from enum import Enum, auto class Color(Enum): WHITE = auto() # 未訪問の頂点 GRAY = auto() # 訪問済みだが, 全ての接点の調査は済んでいない状態の接点 BLACK = auto() # 訪問, 調査済みの接点 n = int(input()) d = [0 for i in range(n)] f = [0 for i in range(n)] colors = [] # 頂点の訪問状態 A = [[0 for j in range(n)] for i in range(n)] # 隣接行列 # 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,054
s339865247
p02238
u138546245
1525938007
Python
Python3
py
Accepted
30
5684
2,338
import abc class AdjacentGraph: """Implementation adjacency-list Graph. Beware ids are between 1 and size. """ def __init__(self, size): self.size = size self._nodes = [[0] * (size+1) for _ in range(size+1)] def set_adj_node(self, id_, adj_id): self._nodes[id_][adj_id] = 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,055
s703240547
p02238
u404682284
1528692311
Python
Python3
py
Accepted
20
5620
958
import sys n = int(input()) input_line = [[int(i) for i in str.split()] for str in sys.stdin.read().splitlines()] for i in range(n): input_line[i] = [] if len(input_line[i]) == 2 else input_line[i][2:] detect_time = [0] * n finish_time = [0] * n is_visit = [False] * n stack = [] time = 0 while(time < n*2): 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,056
s886144234
p02238
u368083894
1528715833
Python
Python3
py
Accepted
20
5660
719
d = None f = None def dfs(g, cur, time): global d, f d[cur] = time for next in g[cur]: if d[next] == 0: time = dfs(g, next, time+1) f[cur] = time + 1 return time + 1 def main(): global d, f n = int(input()) g = [[] for _ in range(n)] d = [0 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,057
s471115012
p02238
u088372268
1529241342
Python
Python3
py
Accepted
20
5812
689
n = int(input()) m = [[0 for j in range(n)] for i in range(n)] color = [0 for i in range(n)] d = [0 for i in range(n)] f = [0 for i in range(n)] time = [0] def dfs(u): color[u] = 1 time[0] += 1 d[u] = time[0] for i in range(n): if m[u][i] == 1 and color[i] == 0: dfs(i) color[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,058
s902316581
p02238
u896240461
1529480376
Python
Python3
py
Accepted
20
5656
551
n = int(input()) g = [] for i in range(n): a = list(map(int,input().split())) g.append(a[2:]) d = [0]*n f = [0]*n global t t = 1 d[0] = 1 x = 1 def find(x): global t if len(g[x-1]) == 0: t += 1 f[x-1] = t else: for i in g[x-1]: if d[i-1] == 0: 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,059
s002666432
p02238
u896240461
1529480492
Python
Python3
py
Accepted
20
5660
529
n = int(input()) g = [] for i in range(n): a = list(map(int,input().split())) g.append(a[2:]) d = [0]*n f = [0]*n global t t = 0 def find(x): global t if len(g[x-1]) == 0: t += 1 f[x-1] = t else: for i in g[x-1]: if d[i-1] == 0: t += 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,060
s821945586
p02238
u848218390
1529481894
Python
Python3
py
Accepted
20
5732
1,099
global t t = 0 class Node: def __init__(self, num, deg, neib): self.num = num self.deg = deg self.neib = neib def dfs(G, d, f, now): #now:1,2,... #print("now:",now) global t t += 1 #print("t:",t) if d[now-1] != 0: t -= 1 #print("has searched or hit roop"...
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,061
s852501072
p02238
u826549974
1529487058
Python
Python3
py
Accepted
20
5744
1,000
n = int(input()) B = [[0 for i in range(n)] for j in range(n)] chk = [0 for i in range(n)] s = [] i_array = [0 for i in range(n)] time = 1 node_start_time = [0 for i in range(n)] node_finish_time = [0 for i in range(n)] for i in range(n): A = list(map(int,input().split())) for j in range(A[1]): B[A[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,062
s020659535
p02238
u055885332
1529643947
Python
Python3
py
Accepted
20
5736
1,202
#16D8101014F KurumeRyunosuke 2018/6/20 n=int(input()) ls=[[0 for i in range(n)]for j in range(n)] for i in range(n): tmp=input().split() for j in range(int(tmp[1])): ls[i][int(tmp[j+2])-1]=1 """ for i in range(n): for j in range(n): if(j!=n-1): print(int(ls[i][j]), end=' ') 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,063
s775872670
p02238
u318430977
1529683138
Python
Python3
py
Accepted
30
5636
635
def dfs(adj, s, d, f, now): now += 1 d[s] = now for t in adj[s]: if t != s and f[t] < 0 and d[t] < 0: d, f, now = dfs(adj, t, d, f, now) now += 1 f[s] = now return d, f, now n = int(input()) adj = [[] for _ in range(n)] for _ in range(n): s = [int(x) for x in input().sp...
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,064
s390194647
p02238
u772417059
1529690572
Python
Python3
py
Accepted
20
5668
531
n=int(input()) next=[[] for i in range(n)] for i in range(n): l=list(map(int,input().split())) u=l[0] k=l[1] for j in range(2,k+2): next[u-1].append(l[j]-1) stk=[] stk.append(0) time=1 d=[0 for i in range(n)] f=[0 for i in range(n)] know=[0 for i in range(n)] def dfs(x): global time know[x]=1 d[x]=time 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,065
s729735083
p02238
u196653484
1529796622
Python
Python3
py
Accepted
20
5692
844
n=0 t=1 def adjacent_matrix(): global n n=int(input()) v=[] array=[] for i in range(n): zero=[0 for i in range(n)] a=list(map(int,input().split())) a=a[2:] for j in a: zero[j-1]=1 array.append(zero) return array def dfs(array,i,d,f): global...
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,066
s708326341
p02238
u684325232
1530008019
Python
Python3
py
Accepted
30
5736
1,222
n=int(input()) l=[[0 for i in range(n)] for j in range(n)]##静的確保 隣接行列 d=[0 for i in range(n)]##発見 f=[0 for i in range(n)]##完了 stack=[]##スタック check=[] for i in range(n): p=[int(x) for x in input().split()] for j in range(n): if j+1 in p[2:]: l[i][j]=1 ##print("---隣接行列---") ##print(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,067
s366044022
p02238
u217703215
1530009195
Python
Python3
py
Accepted
20
5740
972
n=int(input()) a=[[0 for i in range(n)]for j in range(n)] for i in range(n): v=list(input().split()) for j in range(len(v)): v[j]=int(v[j]) x=2 for k in range(v[1]): a[i][v[x+k]-1]=1 #print(a) stack=[] v=[] d=[0]*n f=[0]*n t=1 while len(v)<n: for i in range(n): if i+1 not 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,068
s486676255
p02238
u564105430
1530017954
Python
Python3
py
Accepted
20
5660
429
time=1 n=int(input()) A=[[] for i in range(n)] d=[0 for i in range(n)] f=[0 for i in range(n)] for i in range(n): a=list(map(int,input().split())) for j in range(a[1]): A[i].append(a[2+j]-1) def dfs(q,num): global d,f,time d[num]=time for nx in q[num]: if d[nx]==0: time+=1 dfs(q,nx) time+=1 f[num]=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,069
s139490142
p02238
u408444038
1530064668
Python
Python3
py
Accepted
30
5800
606
cnt = 1 def dep(G,s_cnt,f_cnt,np): global cnt s_cnt[np] = cnt cnt += 1 for i in range(n): if G[np][i] == 1 and s_cnt[i] == 0: dep(G,s_cnt,f_cnt,i) f_cnt[np] = cnt cnt += 1 n = int(input()) G = [[0 for i in range(n)] for j in range(n)] s_cnt = [0 for i in range(n)] f_cnt...
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,070
s289066386
p02238
u252641015
1530079062
Python
Python3
py
Accepted
20
5660
465
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 = ...
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,071
s587520034
p02238
u148477094
1530079113
Python
Python3
py
Accepted
20
5716
234
def d(u): global t C[u]=1;D[u]=t;t+=1 for v in M[u]:v=int(v)-1;C[v]or d(v) F[u]=t;t+=1 N=int(input());R=range(N) M=[input().split()[2:]for _ in R] C,D,F=[0]*N,[0]*N,[0]*N t=1 for i in R:C[i]or d(i) for i in R:print(i+1,D[i],F[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,072
s379116415
p02238
u007270338
1530188457
Python
Python3
py
Accepted
40
6640
1,513
#coding:utf-8 from copy import deepcopy n = int(input()) c = ["white" for i in range(n)] d = [0 for i in range(n)] f = [0 for i in range(n)] S = [] class DFS: def __init__(self, key, color="white",nex=None): self.color = color self.nex = nex self.key = key objListCopy = [DFS(i+1) 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,073
s705130659
p02238
u007270338
1530189158
Python
Python3
py
Accepted
30
6372
1,395
#coding:utf-8 from copy import deepcopy n = int(input()) c = ["white" for i in range(n)] d = [0 for i in range(n)] f = [0 for i in range(n)] S = [] class DFS: def __init__(self, key, color="white",nex=None): self.color = color self.nex = nex self.key = key objList = [DFS(i+1) for i in rang...
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,074
s325734799
p02238
u912237403
1375431979
Python
Python
py
Accepted
20
4312
700
import sys global stamp, counter stamp = {} counter=0 def dfs(key, GRAPH): global stamp, counter if stamp[key][0]==0: counter += 1 stamp[key][0] = counter elif stamp[key][1] !=0: return for e in GRAPH[key]: try: if stamp[e][0] == 0: dfs(e, G...
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,075
s653953514
p02238
u782850731
1380694832
Python
Python
py
Accepted
20
4308
632
#!/usr/bin/env python from __future__ import division, print_function from sys import stdin def walk(index, tm, L, d, f): tm += 1 d[index] = tm for i in L[index]: if not d[i-1]: tm = walk(i-1, tm, L, d, f) tm += 1 f[index] = tm return tm def main(): num = int(stdin.re...
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,076
s679270322
p02238
u140201022
1389304864
Python
Python
py
Accepted
20
4656
672
#!/usr/bin/env python # -*- coding:utf-8 -*- from __future__ import division,print_function import time import sys import io import re import math start = time.clock() i = 0 def walk(index,tm,L,d,f): tm+=1 d[index]=tm for i in L[index]: if not d[i-1]: tm=walk(i-1,tm,L,d,f) tm+=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,077
s000399026
p02238
u327396500
1597762126
Python
Python3
py
Accepted
40
6092
955
import sys input = sys.stdin.readline from collections import deque n = int(input()) graph = {i: deque() for i in range(1, 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) seen = [0]*(n+1) stack = [] time = 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,078
s932246948
p02238
u864060739
1597748988
Python
Python3
py
Accepted
20
5652
624
from sys import stdin input = stdin.readline def DFS(node): global time if discoveredtime[node] == -1: discoveredtime[node] = time time += 1 for child in childlist[node]: DFS(child) finishedtime[node] = time time += 1 N = int(input()) childlist = ...
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,079
s345946842
p02238
u754923116
1597495188
Python
Python3
py
Accepted
20
5716
830
N = int(input()) DG = {} node_ls = [] is_visited = {} #有効グラフをdictで管理することにする for _ in range(N): tmp = input().split() node_id = tmp[0] node_ls.append(node_id) is_visited[node_id] = False adj_num = int(tmp[1])#各頂点の次元が入っている if adj_num != 0: DG[node_id] = tmp[2:] else: DG[node_id...
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,080
s661155139
p02238
u880802684
1597380027
Python
Python3
py
Accepted
20
5712
736
n = int(input()) graph = {} for i in range(1, n + 1): data = input().split() graph[i] = [int(i) for i in data[2:]] class dfs: def __init__(self, graph): self.g = graph self.visited = set() self.time = 0 self.res = {} def dfs(self, cur): self.visited.add(cur) ...
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,081