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
s131907933
p02237
u798796508
1548663604
Python
Python3
py
Accepted
30
6540
304
n = int(input()) A = [list(map(int, input().split())) for _ in range(n)] data = [[0]*(n+1) for _ in range(n+1)] for i in A: #print(i[0]) for j in i[2:]: #print(j) data[i[0]][j] = 1 for i in data[1:]: for j in i[1:-1]: print('{} '.format(j), end='') print(i[-1])
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,882
s502023855
p02237
u803657704
1548131522
Python
Python3
py
Accepted
20
5676
236
N = int(input()) L = [[0]*(N+1) for i in range(N+1)] for i in range(N): D = list(map(int, input().split())) for j in range(2,len(D)): L[D[0]][D[j]] = 1 for i in range(1,N+1): print(' '.join(map(str,L[i][1:])))
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,883
s766358860
p02237
u137545635
1544411602
Python
Python3
py
Accepted
20
5696
1,139
#-*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_A """ import itertools def input_from_txt(number=1): import requests #url = "https://judgedat.u-aizu.ac.jp/testcases/ALDS1_4_A/8/in" url = "https://judgedat.u-aizu.ac.jp/testcases/ALDS1_11_A/%s/in" % number re...
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,884
s236675154
p02237
u978863922
1543929676
Python
Python3
py
Accepted
20
6388
559
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_A&lang=jp # Graph: python3 # 2018.12.04 yonezawa import sys input = sys.stdin.readline #import cProfile def main(): n = int(input()) nmap = [[0 for i in range(n)] for i in range(n)] for _ in range(n): l = list(map(int,input().spl...
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,885
s865320676
p02237
u025180675
1543230189
Python
Python3
py
Accepted
30
7480
422
import collections N = int(input().strip()) Adj = [] for u in range(N): Adju = [0 for _ in range(N)] Adjlst = collections.deque(list(map(int,input().strip().split(" ")))) Adjlst.popleft() K = Adjlst.popleft() for k in range(K): v = Adjlst.popleft() Adju[v-1] = 1 Adj.append(Adju) ...
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,886
s716470607
p02237
u800534567
1542258184
Python
Python3
py
Accepted
20
5608
202
import sys n = int(sys.stdin.readline()) for i in range(n): aa = list(map(int, sys.stdin.readline().split())) c = [0] * n for j in aa[2:]: c[j-1]=1 print(' '.join(map(str,c)))
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,887
s774028661
p02237
u197615397
1542161482
Python
Python3
py
Accepted
20
5684
231
import sys N = int(input()) matrix = [[0]*N for _ in [0]*N] for u, k, *v_a in (map(int, l.split()) for l in sys.stdin): for v in v_a: matrix[u-1][v-1] = 1 print(*(" ".join(map(str, row)) for row in matrix), sep="\n")
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,888
s442802751
p02237
u125481461
1541768383
Python
Python3
py
Accepted
20
5688
382
import sys def main(): n = int(input()) lines = sys.stdin.readlines() outputs = [None] * n str_range = [str(i) for i in range(1, n+1)] for i in range(n): idx, idx_n, *idx_vertices = lines[i].rstrip().split() outputs[i] = ['1' if str_i in idx_vertices else '0' for str_i in str_range] ...
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,889
s100996586
p02237
u498066648
1540089611
Python
Python3
py
Accepted
20
5604
205
n = int(input()) for i in range(n): matrix = [str(0)]*n a = list(map(int, input().split())) if len(a) > 2: for j in a[2:]: matrix[j-1] = str(1) print(' '.join(matrix))
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,890
s394078428
p02237
u637322311
1540021791
Python
Python3
py
Accepted
30
6772
462
from sys import stdin from collections import deque def print_2d_array(A): for i in range(1, len(A)): print(*A[i][1:], sep=" ") def read_and_print_graph(n): A = [ [0]*(n+1) for _ in range(n+1) ] for _ in range(n): line = deque(stdin.readline().strip().split()) i = line.popleft() ...
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,891
s033907141
p02237
u094978706
1539572543
Python
Python3
py
Accepted
20
5672
247
n = int(input()) A = [[0]*n for _ in range(n)] for _ in range(n): tmp = list(map(int, input().split())) u = tmp[0] vs = tmp[2:] for v in vs: A[u-1][v-1] = 1 for i in range(n): print(' '.join(map(str, A[i])))
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,892
s648084012
p02237
u260980560
1539413254
Python
Python3
py
Accepted
20
5604
143
N = int(input()) for i in range(N): u, k, *vs = map(int, input().split()) E = [0]*N for v in vs: E[v-1] = 1 print(*E)
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,893
s045990542
p02237
u760378812
1539367540
Python
Python3
py
Accepted
20
5984
270
n = int(input()) list_m = [[0] * n for i in range(n)] for i in range(n): a,b, *args = map(int,input().split()) for num in args: list_m[a-1][num-1] = 1 for i in range(n): for j in range(n): list_m[i][j] = str(list_m[i][j]) for row in list_m: print(" ".join(row))
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,894
s778258087
p02237
u487861672
1538655068
Python
Python3
py
Accepted
40
7096
727
def read_adj_list(n): al = [None for _ in range(n + 1)] for _ in range(n): u, _, *v = (int(x) for x in input().split()) al[u] = v return al def adj_list_to_matrix(n, al): am = [[0] * (n + 1) for _ in range(n + 1)] for i in range(1, n + 1): for j in al[i]: am[i][...
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,895
s091019804
p02237
u629780968
1537854818
Python
Python3
py
Accepted
30
6388
325
n = int(input()) m = [[0 for i in range(n)] for j in range(n)] for i in range(n): nums = list(map(lambda x:int(x)-1, input().split())) f = nums[0] nums = nums[2:] for num in nums: m[f][num] = 1 for i in range(n): for j in range(n): if(j!=n-1): print(m[i][j], end=' ') else: print(m[i]...
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,896
s873172952
p02237
u697145890
1537706290
Python
Python3
py
Accepted
30
6448
423
from collections import deque from enum import Enum import sys import math BIG_NUM = 2000000000 MOD = 1000000007 EPS = 0.000000001 V = int(input()) table = [['0']*V for i in range(V)] for loop in range(V): tmp_array = list(map(int,input().split())) node_id = tmp_array[0]-1 for i in range(tmp_array[1]):...
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,897
s172018675
p02237
u657361950
1536849183
Python
Python3
py
Accepted
30
6536
294
n = int(input()) a = [[0 for x in range(n)] for x in range(n)] for i in range(n): t = list(map(int, input().split())) x = t[0]-1 for j in range(t[1]): y = t[j+2]-1 a[x][y] = 1 for i in range(n): print(a[i][0],end='') for j in range(1, n): print(' ' + str(a[i][j]),end='') print()
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,898
s935704558
p02237
u183630046
1534399387
Python
Python3
py
Accepted
30
7092
318
n = int(input()) g = [[0 for _ in range(n)] for _ in range(n)] for i in range(n): [*s] = map(int, input().split(' ')) for k in range(s[1]): g[i][s[2 + k] - 1] = 1 for i in range(n): for j in range(n): if j != 0: print(' ', end='') print(g[i][j], end='') print()
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,899
s976923238
p02237
u578148790
1533652622
Python
Python3
py
Accepted
20
5668
249
n = int(input()) m = [[0] * n for i in range(n)] for i in range(n): line = [int(v) for v in input().split()] u = line[0] - 1 for v in line[2:]: v -= 1 m[u][v] = 1 for row in m: print(' '.join([str(v) for v in row]))
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,900
s551329687
p02237
u269568674
1532659681
Python
Python3
py
Accepted
20
6380
265
n = int(input()) rlist = [[]] alist = [[]] for i in range (n): alist.append(input().split()) rlist.append([0]*n) alist.pop(0) rlist.pop(0) for i in range(n): for j in range(2,len(alist[i])): rlist[i][int(alist[i][j])-1] = 1 print(*rlist[i])
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,901
s008427426
p02237
u940395729
1532657809
Python
Python3
py
Accepted
20
6388
313
# coding: utf-8 n = int(input()) G = [[0]*n for i in range(n)] for i in range(n): Adj = list(map(int, input().split())) u = Adj[0]-1 for j in Adj[2:]: G[u][j-1] = 1 # print() for i in range(n): print(*G[i]) # 入力: 隣接リストを与える # 出力: 隣接行列を出力する
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,902
s556508853
p02237
u281836941
1521450827
Python
Python3
py
Accepted
20
6392
203
n=int(input()) table=[[0 for i in range(n)] for i in range(n)] for i in range(n): a=list(map(int,input().split())) for j in a[2:]: table[i][j-1]=1 for i in range(n): print(*table[i])
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,903
s995278660
p02237
u079141094
1468215231
Python
Python3
py
Accepted
20
7716
235
# Graph I - Graph n = int(input()) for _ in range(n): ss = list(map(int, input().split())) u = ss[0] - 1 row = [0 for _ in range(n)] for i in range(ss[1]): idx = 2 + i row[ss[idx]-1] = 1 print(*row)
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,904
s041947050
p02237
u805411170
1418299007
Python
Python3
py
Accepted
40
6724
259
n=int(input()) G=[[0 for i in range(n+1)] for i in range(n+1)] for i in range(n): arr=[int(x) for x in input().split()[2:]] for j in arr: G[i+1][j]=1 for k in range(1,n+1): G[k].pop(0) print(' '.join(map(str, G[k])))
p02237
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Graph</H1> <p> There are t...
4 1 2 2 4 2 1 4 3 0 4 1 3
0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0
28,905
s067008491
p02238
u255317651
1531401916
Python
Python3
py
Accepted
20
5632
979
# -*- coding: utf-8 -*- """ Created on Sun Jul 8 10:56:33 2018 @author: maezawa """ n = int(input()) adj = [[] for _ in range(n)] d = [0 for _ in range(n)] f = [0 for _ in range(n)] for j in range(n): ain = list(map(int, input().split())) u = ain[0] k = ain[1] for i in range(k): adj[u-1].appe...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,906
s200567488
p02238
u684241248
1531475033
Python
Python3
py
Accepted
30
5812
1,168
# -*- coding: utf-8 -*- class Graph: def __init__(self, n, adj_matrix): self.n = n self.adj_matrix = adj_matrix def show(self): for _ in self.adj_matrix: print(*_) def dfs(self): self.states = [2] * self.n self.d = [None] * self.n self.f = [Non...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,907
s188289564
p02238
u424720817
1531973739
Python
Python3
py
Accepted
20
5812
550
n = int(input()) graph = [[0 for i in range(n)] for j in range(n)] d = [0] * n f = [0] * n g = [0] * n time = 0 for i in range(n): a = list(map(int, input().split())) for j in range(0, a[1], 1): graph[a[0] - 1][a[2 + j] - 1] = 1 def search(i): global time time = time + 1 d[i] = time g[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,908
s615475387
p02238
u424720817
1532060483
Python
Python3
py
Accepted
20
5808
550
n = int(input()) graph = [[0 for i in range(n)] for j in range(n)] d = [0] * n f = [0] * n g = [0] * n time = 0 for i in range(n): a = list(map(int, input().split())) for j in range(0, a[1], 1): graph[a[0] - 1][a[2 + j] - 1] = 1 def search(i): global time time = time + 1 d[i] = time g[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,909
s855069754
p02238
u279605379
1534728826
Python
Python3
py
Accepted
30
5628
451
def dfs(n): global t S[n] = t DP[n]=1 for i in A[n][2:]: if not DP[i]: t += 1 dfs(i) t += 1 F[n] = t n = int(input()) A = [0]*(n+1) S = [0]*(n+1) F = [0]*(n+1) DP = [0]*(n+1) for i in range(n): A[i+1] = [int(i) for i in input().split()] t = 0 for i in range(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,910
s201068838
p02238
u153665391
1534910778
Python
Python3
py
Accepted
20
5764
741
def dfs(): tt = 0 for u in range(N): if colors[u] == WHITE: tt = dfs_visit(u, tt) def dfs_visit(u, tt): tt += 1 colors[u] = GLAY d[u] = tt for v in range(N): if adjacency_list[u][v] == 1 and colors[v] == WHITE: tt = dfs_visit(v, tt) tt += 1 colors...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,911
s382848852
p02238
u153665391
1534911125
Python
Python3
py
Accepted
20
5748
659
def depth_search(u, t): t += 1 s.append(u) d[u] = t for v in range(N): if adjacency_list[u][v] == 0: continue if d[v] == 0 and v not in s: t = depth_search(v, t) t += 1 s.pop() f[u] = t return t N = int(input()) adjacency_list = [[0 for j 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
28,912
s136410577
p02238
u007270338
1535602067
Python
Python3
py
Accepted
20
5812
744
#coding: utf-8 n = int(input()) color = ["white" for i in range(n)] d = [[] for i in range(n)] global t t = 0 M = [[False for i in range(n)] for j in range(n)] for i in range(n): data = list(map(int,input().split())) u = data[0] k = data[1] if i == 0: start = u for v in data[2:2+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
28,913
s736541457
p02238
u726330006
1540440016
Python
Python3
py
Accepted
30
5780
1,080
#graphの頂点vertex(インデックス、0オリジン)を深さ優先探索。dis_time:最初に訪れた時のtimeを管理するリスト #fin_time:その頂点に対して、探索が終わった時のtimeを管理するリスト tmp_time:現在のtime(関数内で変更できるようにリスト) def DPS(graph,vertex,dis_time,fin_time,tmp_time): tmp_time[0]+=1 dis_time[vertex]=tmp_time[0] for i in range(len(graph[0])): if(graph[vertex][i] !=0 and dis_...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,914
s717306292
p02238
u094978706
1540965516
Python
Python3
py
Accepted
20
5636
628
n = int(input()) adj = [0]*n # adjacent list for i in range(n): tmp = list(map( int, input().split() ) ) adj[tmp[0]-1] = list(map(lambda x : x - 1, tmp[2:])) c = ['w']*n # color of each vertex d = [0]*n # discovery time for each vertex f = [0]*n # finish time for each vertex time = 0 def DFS_visit(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
28,915
s374418875
p02238
u467648242
1546000642
Python
Python3
py
Accepted
20
5660
702
n = int(input()) graph = [[] for _ in range(n)] for i in range(n): in_list = list(map(int, input().split())) u = in_list[0] graph[u - 1] = in_list[2:] d = [0 for _ in range(n)] f = [0 for _ in range(n)] time = 0 def dfs(now, prev, graph, d, f): if d[now] != 0: return d, f global time t...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
4 1 1 2 2 1 4 3 0 4 1 3
1 1 8 2 2 7 3 4 5 4 3 6
28,916
s091831804
p02238
u467648242
1546001181
Python
Python3
py
Accepted
30
5728
746
n = int(input()) graph = [[] for _ in range(n)] for i in range(n): in_list = list(map(int, input().split())) u = in_list[0] graph[u - 1] = in_list[2:] d = [0 for _ in range(n)] f = [0 for _ in range(n)] time = 0 def dfs(now, prev, graph, d, f, time): if d[now] != 0: return d, f, time 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
28,917
s391921712
p02238
u165578704
1556424322
Python
Python3
py
Accepted
20
5684
746
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10 ** 9) def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) INF=float('inf') N=INT() nodes=[[] 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
28,918
s308699505
p02238
u357267874
1556506974
Python
Python3
py
Accepted
20
5804
708
n = int(input()) A = [[0 for i in range(n)] for j in range(n)] for i in range(n): u, k, *v = list(map(int, input().split())) for j in v: A[int(u)-1][int(j)-1] = 1 # A[int(j)-1][int(u)-1] = 1 # for row in A: # msg = ' '.join(map(str, row)) # # print(msg) d = [-1] * n f = [-1] * n 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
28,919
s482214093
p02238
u357267874
1556541035
Python
Python3
py
Accepted
20
5748
2,195
n = int(input()) A = [[0 for i in range(n)] for j in range(n)] for i in range(n): u, k, *v = list(map(int, input().split())) for j in v: A[int(u)-1][int(j)-1] = 1 # A[int(j)-1][int(u)-1] = 1 for row in A: msg = ' '.join(map(str, row)) # print(msg) d = [-1] * n f = [-1] * n t = 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,920
s124041365
p02238
u357267874
1556582851
Python
Python3
py
Accepted
20
5796
508
# input n = int(input()) A = [[0 for i in range(n)] for j in range(n)] for i in range(n): u, k, *v_list = list(map(int, input().split())) for v in v_list: A[u-1][v-1] = 1 # init d = [0] * n f = [0] * n t = 0 # recursive def dfs(u): global t t += 1 d[u] = t for v in range(n): 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,921
s998331381
p02238
u970810709
1559108540
Python
Python3
py
Accepted
20
5656
947
n = int(input()) G = [[] for _ in range(n)] u1 = 0 for _ in range(n): u, k, *v = [int(i) for i in input().split()] G[u - 1] = v if k != 0 and u1 == 0: u1 = u time = 1 u = u1 D = [] out = [[i+1, 0, 0] for i in range(n)] T = [] while True: if u not in D: out[u - 1][1] = time D.app...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,922
s626210665
p02238
u821080069
1559554130
Python
Python3
py
Accepted
20
5720
816
n = int(input()) graph = [[] for _ in range(n)] global time global visited global f_time global e_time time = 1 visited = [0 for _ in range(n)] f_time = [0 for _ in range(n)] e_time = [0 for _ in range(n)] def input_graph(n): for _ in range(n): node_id, num, *v = list(map(int, input().split())) 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
28,923
s528679848
p02238
u198069342
1416305119
Python
Python
py
Accepted
20
4268
284
def d(r): global n if t[r]:return n+=1 t[r]=[r+1,n] for i in c[r]:d(i-1) n+=1 t[r][2:]=[n] m=input() c=[0]*m for _ in range(m): l=map(int,raw_input().split()) c[l[0]-1]=l[2:] n=0 t=[0]*m for i in range(m): d(i) print " ".join(map(str,t[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,924
s015253960
p02238
u567380442
1422362328
Python
Python3
py
Accepted
40
6728
459
def depth_search(i, adj, d, f, t): if d[i - 1]: return t d[i - 1] = t t += 1 for v in adj[i - 1]: t = depth_search(v, adj, d, f, t) f[i - 1] = t t += 1 return t n = int(input()) adj = [list(map(int, input().split()))[2:] for _ in range(n)] d = [0] * n f = [0] * n t = 1 for ...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
4 1 1 2 2 1 4 3 0 4 1 3
1 1 8 2 2 7 3 4 5 4 3 6
28,925
s478591556
p02238
u809822290
1435898025
Python
Python3
py
Accepted
40
6808
555
from sys import stdin X = [ 0 for i in range(100) ] d = [ 0 for i in range(100) ] f = [ 0 for i in range(100) ] G = [[ 0 for i in range(100) ] for i in range(100)] t = 0 def DFS(i) : global t t += 1 d[i] = t for j in range(n) : if G[i][j] != 0 and d[j] == 0 : DFS(j) t += 1 f[i] = t n = int(input()) for i 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,926
s848341586
p02238
u689297737
1436676896
Python
Python
py
Accepted
20
4392
2,734
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B # Depth First Search # Result: import sys class Graph(object): def __init__(self, size): super(Graph, self).__init__() self.__size = size self.__vertices = [None] * size def add_vertex(self, vertex): self.__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
28,927
s369482250
p02238
u882992966
1442806264
Python
Python3
py
Accepted
50
7928
3,674
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys WHITE = 0 GRAY = 1 BLACK = 2 def dbg_record(records): for index, record in enumerate(records): print("???????????????: %d" % index) if isinstance(record, dict): print("??\??????: %d" % record.get("visit", -1)) prin...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,928
s019835274
p02238
u882992966
1442810092
Python
Python3
py
Accepted
50
7968
3,742
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # ??????: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B import sys WHITE = 0 GRAY = 1 BLACK = 2 def dbg_record(records): for index, record in enumerate(records): print("???????????????: %d" % index) if isinstance(record, dict)...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,929
s157349383
p02238
u881590806
1450662216
Python
Python
py
Accepted
30
6408
628
n = int(raw_input()) def dfs(u,t): global graph global found global timestamp if u in found: return t found.add(u) timestamp[u] = [-1,-1] timestamp[u][0] = t t += 1 for v in graph[u]: t = dfs(v,t) timestamp[u][1] = t t += 1 return t graph = [[] 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
28,930
s644273409
p02238
u669284080
1451226192
Python
Python3
py
Accepted
30
7792
608
#!/usr/bin/python3 def find(A, id, V, time): i = id - 1 A[i][0] = True A[i][1] = time time += 1 for v in V[i]: if A[v - 1][0] == False: time = find(A, v, V, time) A[i][2] = time time += 1 return time n = int(input()) # [isFind, d, f] A = [[False, 0, 0] 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
28,931
s401846420
p02238
u069446126
1453896237
Python
Python
py
Accepted
10
6604
766
def DFS(n = 1, A = [0], i = 0, d = [0], f = [0], time = 1): for j in range(n): if A[i][j] == 1 and d[j] == 0: time = time + 1 d[j] = time time = DFS(n, A, j, d, f, time) time = time + 1 f[i] = time return time n = int(raw_input()) A = [0] * n 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
28,932
s706523464
p02238
u069446126
1453896309
Python
Python
py
Accepted
10
6608
758
def DFS(A = [0], i = 0, d = [0], f = [0], time = 1): for j in range(len(d)): if A[i][j] == 1 and d[j] == 0: time = time + 1 d[j] = time time = DFS(A, j, d, f, time) time = time + 1 f[i] = time return time n = int(raw_input()) A = [0] * 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
28,933
s703518945
p02238
u069446126
1453896554
Python
Python
py
Accepted
10
6600
721
def DFS(n = 1, i = 0, time = 1): for j in range(n): if A[i][j] == 1 and d[j] == 0: time = time + 1 d[j] = time time = DFS(n, j, time) time = time + 1 f[i] = time return time n = int(raw_input()) A = [0] * n for i in range(n): A[i] = [0] * n for i in ran...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,934
s328856552
p02238
u920118302
1453958641
Python
Python
py
Accepted
10
6480
623
def DFS(s, t): t += 1 flag[s] = 1 d[s] = t for i in range(1, n+1): if G[s][i] == 1: if flag[i] == 0: DFS(i, t) t = f[i] f[s] = t + 1 n = int(raw_input()) G = [[0 for i in range(n+1)] for j in range(n+1)] d = [0 for i in range(n+1)] f = [0 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
28,935
s009755142
p02238
u885467869
1454071302
Python
Python
py
Accepted
10
6488
966
class node: def __init__(self): self.number = 0 self.in_time = 0 self.out_time = 0 self.link_node = [] self.is_serched = False def dfs_visit(node, timer): node.in_time = timer node.is_serched = True temp = timer + 1 for item in node.link_...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,936
s335361425
p02238
u119456964
1454079327
Python
Python
py
Accepted
10
6480
660
n = int(raw_input()) d = [0 for i in range(n)] f = [0 for i in range(n)] G = [0 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] st = [0 for i in range(n)] t = [0] def DFS_visit(s): st[s] = 1 t[0] += 1 d[s] = t[0] for e in range(n): if M[s][e] == 1 and st[e] == 0: 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
28,937
s948625413
p02238
u828153094
1454144774
Python
Python
py
Accepted
10
6476
714
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...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,938
s402740920
p02238
u797673668
1454252614
Python
Python3
py
Accepted
20
7800
589
n = int(input()) g = [None] * n visited = [0] * n root = set(range(n)) ts = [[0, 0] for _ in range(n)] t = 0 while n: l = list(map(int, input().split())) connected = [i - 1 for i in l[2:]] g[l[0] - 1] = [i - 1 for i in l[2:]] root -= set(connected) n -= 1 def dfs(i): global g, t, ts, 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
28,939
s975508492
p02238
u655651061
1454322869
Python
Python
py
Accepted
20
6504
407
import sys def DFS(index, tm, l, a, b): tm += 1 a[index] = tm for i in l[index]: if not a[i-1]: tm = DFS(i-1, tm, l, a, b) tm += 1 b[index] = tm return tm n = input() l=[] for i in xrange(n): l.append([int(s) for s in sys.stdin.readline().split()[2:]]) a = [0] * n b = [0] * n tm = 0 for i in xrange(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
28,940
s743115155
p02238
u970436839
1454340518
Python
Python
py
Accepted
10
6592
665
n = int(raw_input()) d = [0 for i in range(n)] f = [0 for i in range(n)] G = [0 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] st = [0 for i in range(n)] t = [0] def DFS_visit(s): st[s] = 1 t[0] += 1 d[s] = t[0] for e in range(n): if M[s][e] == 1 and st[e] == 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,941
s258870613
p02238
u970436839
1454340765
Python
Python
py
Accepted
10
6488
669
n = int(raw_input()) d = [0 for i in range(n)] f = [0 for i in range(n)] G = [0 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] col = [0 for i in range(n)] t = [0] def DFS_visit(u): col[u] = 1 t[0] += 1 d[u] = t[0] for v in range(n): if M[u][v] == 1 and col[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
28,942
s597239197
p02238
u078762447
1454344875
Python
Python
py
Accepted
10
6496
416
import sys def dfs(i, t, l, a, b): t += 1 a[i] = t for j in l[i]: if not a[j-1]: t = dfs(j-1, t, l, a, b) t += 1 b[i] = t return t n = input() l=[] for i in range(n): l.append([int(s) for s in sys.stdin.readline().split()[2:]]) a = [0] * n b = [0] * n t = 0 for i in xrange(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
28,943
s873092075
p02238
u834416077
1454401744
Python
Python
py
Accepted
10
6508
626
n = int(raw_input()) d = [0 for i in range(n)] f = [0 for i in range(n)] G = [0 for i in range(n)] v = [[0 for i in range(n)] for j in range(n)] st = [0 for i in range(n)] tm = [0] def DFS_visit(s): st[s] = 1 tm[0] += 1 d[s] = tm[0] for e in range(n): if v[s][e] == 1 and st[e] == 0: DFS_visit(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
28,944
s715172336
p02238
u824204304
1454407471
Python
Python
py
Accepted
10
6412
690
n = int(raw_input()) d = [0 for i in range(n)] f = [0 for i in range(n)] a = [[0 for i in range(n)] for j in range(n)] st = [0 for i in range(n)] time = [0] G = [0 for i in range(n)] def dfs_visit(s): st[s] = 1 time[0] += 1 d[s] = time[0] for k in range(n): if a[s][k] == 1 and st[k] == 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,945
s349341730
p02238
u824204304
1454407479
Python
Python
py
Accepted
30
6484
690
n = int(raw_input()) d = [0 for i in range(n)] f = [0 for i in range(n)] a = [[0 for i in range(n)] for j in range(n)] st = [0 for i in range(n)] time = [0] G = [0 for i in range(n)] def dfs_visit(s): st[s] = 1 time[0] += 1 d[s] = time[0] for k in range(n): if a[s][k] == 1 and st[k] == 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,946
s789493505
p02238
u630265299
1454413810
Python
Python
py
Accepted
10
6492
683
n = int(raw_input()) d = [0 for i in range(n)] f = [0 for i in range(n)] a = [[0 for i in range(n)] for j in range(n)] st = [0 for i in range(n)] time = [0] g = [0 for i in range(n)] def dfs_visit(s): st[s] = 1 time[0] += 1 d[s] = time[0] for k in range(n): if a[s][k] == 1 and st[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
28,947
s410663397
p02238
u613805578
1454414950
Python
Python
py
Accepted
10
6516
670
n = int(raw_input()) d = [0 for i in range(n)] f = [0 for i in range(n)] G = [0 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] st = [0 for i in range(n)] t = [0] def DFS_visit(s): st[s] = 1 t[0] += 1 d[s] = t[0] for e in range(n): if M[s][e] == 1 and st[e] == 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,948
s892919246
p02238
u334643297
1454415462
Python
Python
py
Accepted
10
6400
548
n = int(raw_input()) t = [0] d = [0 for i in range(n)] f = [0 for i in range(n)] G = [0 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] st = [0 for i in range(n)] def DFS_visit(s): st[s] = 1 d[s] = t[0] = t[0] + 1 for e in range(n): if M[s][e] == 1 and st[e] == 0: DFS_visit(e) f[s] = t[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,949
s153967932
p02238
u393769849
1454415875
Python
Python
py
Accepted
10
6472
427
import sys def dfs(i, t, l, a, b): t += 1 a[i] = t for j in l[i]: if not a[j-1]: t = dfs(j-1, t, l, a, b) t += 1 b[i] = t return t n = input() l=[] for i in range(n): l.append([int(s) for s in sys.stdin.readline().split()[2:]]) a = [0] * n b = [0] * n t = 0 for i in xra...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,950
s099280818
p02238
u563876281
1454417945
Python
Python
py
Accepted
10
6584
651
def depth(s, time): time += 1 flag[s] = 1 d[s] = time for i in range(1, n+1): if G[s][i] == 1: if flag[i] == 0: depth(i, time) time = f[i] f[s] = time + 1 n = int(raw_input()) G = [[0 for i in range(n+1)] for j in range(n+1)] d = [0 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
28,951
s671367487
p02238
u967035362
1454418844
Python
Python
py
Accepted
10
6856
629
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 f[index]=tm return tm def main(): 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
28,952
s668766515
p02238
u000228958
1454420769
Python
Python
py
Accepted
30
6488
715
n = input() time = [] time.append(0) d = [0 for i in xrange(n + 1)] f = [0 for i in xrange(n + 1)] color = ['WHITE' for i in xrange(n + 1)] graph_map = [[0 for j in xrange(n + 1)] for i in xrange(n + 1)] for i in xrange(1, n + 1): tmp = map(int, raw_input().split()) for j in xrange(tmp[1]): graph_ma...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,953
s905278552
p02238
u663227983
1454421798
Python
Python
py
Accepted
10
6472
361
n=0 m=input() c=[0 for i in xrange(m)] t=[0 for i in xrange(m)] def d(u): global n if t[u]:return n = n + 1 t[u]=[u+1,n] for i in c[u]:d(i-1) n = n + 1 t[u][2:]=[n] def dfs(): for i in range(m): l=map(int,raw_input().split()) c[l[0]-1]=l[2:] for i in range(m): 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
28,954
s450021234
p02238
u663227983
1454421910
Python
Python
py
Accepted
10
6468
366
n=0 m=input() c=[0 for i in xrange(m)] ts=[0 for i in xrange(m)] def d(u): global n if ts[u]:return n = n + 1 ts[u]=[u+1,n] for i in c[u]:d(i-1) n = n + 1 ts[u][2:]=[n] def dfs(): for i in range(m): l=map(int,raw_input().split()) c[l[0]-1]=l[2:] for i in range(m): 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
28,955
s384091383
p02238
u663227983
1454421968
Python
Python
py
Accepted
10
6472
390
n=0 m=input() c=[0 for i in xrange(m)] ts=[0 for i in xrange(m)] def dfs_visit(u): global n if ts[u]:return n = n + 1 ts[u]=[u+1,n] for i in c[u]:dfs_visit(i-1) n = n + 1 ts[u][2:]=[n] def dfs(): for i in range(m): l=map(int,raw_input().split()) c[l[0]-1]=l[2:] 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
28,956
s334337137
p02238
u038005340
1454422659
Python
Python
py
Accepted
10
6488
691
n = int( raw_input() ) d = [ 0 for i in range(n) ] f = [ 0 for i in range(n) ] G = [ 0 for i in range(n) ] v = [ [0 for i in range(n) ] for j in range(n) ] st = [ 0 for i in range(n) ] tm = [ 0 ] def DFS_visit(s): st[ s ] = 1 tm[ 0 ] += 1 d[ s ] = tm[ 0 ] for e in range(n): if v[ s ][ e ] == 1 and 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,957
s846682855
p02238
u038243492
1454422696
Python
Python
py
Accepted
10
6500
635
n = int(raw_input()) def dfs(u,t): global graph global found global timestamp if u in found: return t found.add(u) timestamp[u] = [-1,-1] timestamp[u][0] = t t += 1 for v in graph[u]: t = dfs(v,t) timestamp[u][1] = t t += 1 return t graph = [[] 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
28,958
s244994436
p02238
u424209323
1454423804
Python
Python
py
Accepted
10
6496
778
n = input() d = [0 for i in range(n)] f = [0 for i in range(n)] G = [0 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] color = [0 for i in range(n)] tt = [0] WHITE = 0 GRAY = 1 BLACK = 2 def dfs_visit(u): color[u] = GRAY tt[0] = tt[0] + 1 d[u] = tt[0] for v 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
28,959
s431833623
p02238
u177808190
1454423811
Python
Python
py
Accepted
30
6604
898
n = int(raw_input()) N = 100 WHITE = 0 GRAY = 1 BLACK = 2 Color = [WHITE for i in range(n)] #M = [[0 for i in range(N)] for j in range(N)] tt = 0 d = [0 for i in range(n)] f = [0 for i in range(n)] def dfs_visit(u): Color[u] = GRAY global tt tt += 1 d[u] = tt for v in range(n): if M[u][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
28,960
s445071387
p02238
u803327846
1454424232
Python
Python
py
Accepted
10
6476
683
n = int(raw_input()) d = [0 for i in range(n)] f = [0 for i in range(n)] a = [[0 for i in range(n)] for j in range(n)] st = [0 for i in range(n)] time = [0] g = [0 for i in range(n)] def dfs_visit(s): st[s] = 1 time[0] += 1 d[s] = time[0] for k in range(n): if a[s][k] == 1 and st...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,961
s837062689
p02238
u619765879
1454424296
Python
Python
py
Accepted
10
6508
613
def visit(u): global t flag[u] = 1 t += 1 s[u] = t for v in range(n): if M[u][v]==0: continue if flag[v]==0: visit(v) flag[u] = 2 t += 1 e[u] = t def dfs(): for u in range(n): if flag[u]==0: visit(u) for u in range(n): print '%d %d %d' % (u+1, s[u], e[u]) n = 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
28,962
s354884642
p02238
u536494052
1454424972
Python
Python
py
Accepted
30
6796
674
#!/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
28,963
s278017070
p02238
u885889402
1454427783
Python
Python3
py
Accepted
60
7872
680
T = [0] def curserch(N,k,T,P,n): T[0] = T[0]+1 P[k]["d"] = T[0] for i in range(1,n+1): if N[k][i]==1 and P[i]["d"]==0: curserch(N,i,T,P,n) T[0] = T[0]+1 P[i]["f"]=T[0] n = int(input()) A = [[0 for j in range(n+1)] for i in range(n+1)] for i in range(n): v...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
4 1 1 2 2 1 4 3 0 4 1 3
1 1 8 2 2 7 3 4 5 4 3 6
28,964
s309293608
p02238
u341533698
1454961498
Python
Python
py
Accepted
10
6484
800
n = int(raw_input()) d = [0] * n f = [0] * n M = [[0]*n for _ in xrange(n)] color = [0] * n tt = 0 WHITE = 0 GRAY = 1 BLACK = 2 def dfs_visit(u): global tt color[u] = GRAY tt += 1 d[u] = tt for v in xrange(n): if M[u][v] == 0: continue if color[v] == WHITE: ...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,965
s468376539
p02238
u341533698
1454962398
Python
Python
py
Accepted
10
6752
1,173
from collections import deque n = int(raw_input()) d = [0] * n f = [0] * n M = [[0]*n for _ in xrange(n)] color = [0] * n tt = 0 WHITE = 0 GRAY = 1 BLACK = 2 nt = [0] * n def next(u): for v in xrange(nt[u],n): nt[u] = v + 1 if M[u][v] == 1: return v return -1 def dfs_visit(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
28,966
s496101002
p02238
u408260374
1455857795
Python
Python3
py
Accepted
40
7792
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 = [-...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,967
s880366245
p02238
u731710433
1457252055
Python
Python3
py
Accepted
40
7812
772
n = int(input()) mat = [[0] * n for _ in range(n)] d, f = [0] * n, [0] * n for _ in range(n): adj = list(map(int, input().split())) i = adj[0] v = adj[2:] for j in v: mat[i - 1][j - 1] = 1 time, current = 0, 0 stack = [] while 0 in f: if not stack: for i, v in enumerate(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
28,968
s796502288
p02238
u894114233
1458896947
Python
Python
py
Accepted
20
6552
572
def dfs(u): global time time+=1 color[u]='gray' d[u]+=time for v in xrange(n): if m[u][v]!=0 and color[v]=="white": dfs(v) time+=1 color[u]="black" f[u]+=time n=input() info=[0]*n color=["white"]*n m=[[0]*n for _ in xrange(n)] d=[0]*n f=[0]*n for i in xrange(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
28,969
s991782134
p02238
u567281053
1463070035
Python
Python
py
Accepted
30
6396
585
import sys def dfs(i): global V, t, d, f if d[i] != 0: return d[i] = t t += 1 for v in V[i]: dfs(v) f[i] = t t += 1 return lines = sys.stdin.readlines() n = int(lines[0]) V = [[] for _ in range(n + 1)] for i in range(1, n + 1): v = map(int, lines[i].split()) ...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,970
s451774508
p02238
u072053884
1463296731
Python
Python3
py
Accepted
20
7760
889
"""Depth First Search.""" n = int(input()) adj = [None] for i in range(n): adj_i = list(map(int, input().split()[2:])) adj.append(adj_i) # searched or not, number of vertex, discovery time and finishing time. sndf = [None] for i in range(1, n + 1): sndf.append([False, i]) path = [] time = 0 def dfs(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
28,971
s521337924
p02238
u072053884
1463311402
Python
Python3
py
Accepted
20
7772
604
n = int(input()) adj = [None] for i in range(n): adj_i = list(map(int, input().split()[2:])) adj.append(adj_i) # searched or not, number of vertex, discovery time and finishing time. sndf = [None] for i in range(1, n + 1): sndf.append([False, i]) path = [] time = 0 def dfs(u): global time sndf[...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,972
s936101836
p02238
u072053884
1463364597
Python
Python3
py
Accepted
10
7748
582
n = int(input()) adj = [None] for i in range(n): adj_i = list(map(int, input().split()[2:])) adj.append(adj_i) # searched or not, number of vertex, discovery time and finishing time. sndf = [None] for i in range(1, n + 1): sndf.append([False, i]) path = [] time = 0 def dfs(u): global time sndf[...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,973
s294416041
p02238
u569960318
1467869823
Python
Python3
py
Accepted
30
7792
481
def DFS(G): ans = [0] + [[0,0,0] for _ in range(len(G))] def main(G,i): ans[0] += 1 ans[i] = [i, ans[0], ans[0]] for j in sorted(G[i-1][2:]): if ans[j][0] == 0: main(G,j) ans[0] += 1 ans[i][2] = ans[0] for u in G: if ans[u[0]][0] == 0: main(G,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
28,974
s511282156
p02238
u881590806
1469460084
Python
Python
py
Accepted
10
6504
873
class Node: def __init__(self,v): self.v = v self.c = [] def dfs(n,f,d,t,visited): visited.add(n.v) f[n.v] = t t2 = t for c in sorted(n.c,key=lambda x:x.v): if not c.v in visited: t2 = dfs(c,f,d,t2+1,visited) d[n.v] = t2+1 return t2+1 n = int(raw_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
28,975
s479827039
p02238
u027872723
1476695253
Python
Python3
py
Accepted
30
7852
1,044
# -*- coding: utf_8 -*- level = False def debug(v): if level: print(v) n = int(input()) a = [0] for i in range(n): v = input().split() v.pop(0) v.pop(0) a.append([int(x) for x in v]) debug(a) stack = [1] results = [[0 for i in range(2)] for j in range(n + 1)] results[0][0] = 0 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
28,976
s400378781
p02238
u890722286
1478299643
Python
Python3
py
Accepted
30
7804
591
time = 0 def dfs_visit(g, u): global time time += 1 u[2] = time u[1] = 'g' for v in u[0]: ch = g[v] if ch[1] == 'w': ch[4] = u[5] dfs_visit(g, ch) u[1] = 'b' time += 1 u[3] = time n = int(input()) g = {} s = 0 stack = [] 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
28,977
s921825195
p02238
u022407960
1479653215
Python
Python3
py
Accepted
50
7816
2,667
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 def generate_adj(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[int(v_deta...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
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,978
s327064769
p02238
u022407960
1479653467
Python
Python3
py
Accepted
30
7852
2,356
#!/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[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,979
s268738112
p02238
u022407960
1479653919
Python
Python3
py
Accepted
50
7936
2,386
#!/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[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,980
s028186729
p02238
u022407960
1479657048
Python
Python3
py
Accepted
40
7924
2,450
#!/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,981