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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s599269615 | p02238 | u454636644 | 1557576779 | Python | Python3 | py | Accepted | 20 | 5792 | 739 | import sys
time = 0
def dfs(u):
global time
flag_list[u] = 1
time += 1
d_list[u] = time
for v in range(n):
if m_list[u][v] == 1 and flag_list[v] == 0:
dfs(v)
flag_list[u] = 2
time += 1
f_list[u] = time
input = sys.stdin.readline
n = int(input())
m_list = [[0]*n for... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,282 |
s135826405 | p02238 | u805716376 | 1556966654 | Python | Python3 | py | Accepted | 20 | 5648 | 430 | n = int(input())
a = []
for i in range(n):
a += [list(map(int, input().split()))[2:]]
cnt = 1
pre = [0]*n
aft = [0]*n
color = [0]*n
def dfs(s):
global cnt
pre[s-1] = cnt
cnt += 1
color[s-1] = 1
for i in a[s-1]:
if color[i-1] == 0:dfs(i)
aft[s-1] = cnt
cnt += 1
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,283 |
s475106996 | p02238 | u967553879 | 1555042380 | Python | Python3 | py | Accepted | 20 | 5740 | 745 |
n = int(input())
g_list = {}
for _ in range(n):
n1, num, *cl = map(int, input().split())
g_list[n1] = cl
# 深さ優先探索: クラス使って書く?
class Graph():
def __init__(self, g_list):
self.time = 0
self.nodes = {}
self.d = {}
self.f = {}
self.g_list = g_list
def dfs(self, nod... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,284 |
s251119668 | p02238 | u597769560 | 1554519004 | Python | Python3 | py | Accepted | 20 | 5652 | 700 | # -*- coding: utf-8 -*-
"""
Created on Sat Apr 6 11:36:14 2019
@author: Yamazaki Kenichi
"""
n = int(input())
A = [[]]
A = A + [list(map(int,input().split())) for i in range(n)]
def dfs(k):
global counta
for i in range(A[k][1]):
if T[A[k][i+2]][0] == -1:
T[A[k][i+2]][0] = 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,285 |
s458627049 | p02238 | u062898953 | 1554182178 | Python | Python3 | py | Accepted | 20 | 5728 | 482 | n = int(input())
g = [[0]*(n+1) for _ in range(n+1)]
for i in range(n):
u, k, *v, = map(int, input().split())
for vi in v:
g[u][vi] = 1
d = [0]*(n+1)
f = [0]*(n+1)
t = 0
def dfs(u):
global t
if d[u] != 0:
return
t += 1
d[u] = t
for i, v in enumerate(g[u]):
if 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,286 |
s906970340 | p02238 | u065504661 | 1553953115 | Python | Python3 | py | Accepted | 20 | 5704 | 1,071 | n = int(input())
adj = [[None for _ in range(n)] for _ in range(n)]
for i in range(n):
l = list(map(int, input().split()))
if l[1] == 0:
continue
else:
for j in range(2,len(l)):
adj[l[0]-1][l[j]-1] = 1
color = ['white' for _ in range(n)]
d = [None for _ in range(n)]
f = [None fo... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,287 |
s691305534 | p02238 | u394181453 | 1552499290 | Python | Python3 | py | Accepted | 20 | 6036 | 777 | from collections import defaultdict
n = int(input())
rel = defaultdict(set)
times = {}
for _ in range(n):
rl = list(map(int, input().split()))
p, ts = rl[0], rl[2:]
rel[p] = sorted(ts, reverse=True)
times[p] = {'first': 0, 'last': 0}
t = 0
for f in range(1, len(rel)+1):
if times[f]['last']:
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,288 |
s583308137 | p02238 | u276288047 | 1552017597 | Python | Python3 | py | Accepted | 20 | 5628 | 597 | # coding: utf-8
visited = [False]*101
discovery_time = [0]*101
finish_time = [0]*101
A = [[] for _ in range(101)]
time = 0
def dfs(n):
global time
if visited[n] == True:
return
time += 1
discovery_time[n] = time
visited[n] = True
for i in A[n]:
dfs(i)
time += 1
finish_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,289 |
s284101423 | p02238 | u637322311 | 1550981616 | Python | Python3 | py | Accepted | 30 | 6136 | 968 | from sys import stdin
from collections import deque
def read_graph(n):
A = [ [0]*(n+1) for _ in range(n+1) ]
for _ in range(n):
line = deque(stdin.readline().strip().split())
i = line.popleft()
line.popleft()
for k in line:
A[int(i)][int(k)] = 1
return A
def dfs... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,290 |
s883791747 | p02238 | u415714413 | 1550820612 | Python | Python3 | py | Accepted | 20 | 5632 | 747 | import sys
readline = sys.stdin.readline
write = sys.stdout.write
n = int(input())
G = [None for i in range(n+1)]
for i in range(n):
node_id, k, *adj = map(int, readline().split())
# adj.sort()
G[node_id] = adj
begin = [0,]*(n+1)
end = [0,]*(n+1)
time = 1
def dfs(v):
global time
begin[v] = 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,291 |
s429065854 | p02238 | u798796508 | 1548694602 | Python | Python3 | py | Accepted | 20 | 5772 | 635 | def dfs(u):
global time
color[u] = 'Gray'
time += 1
d[u] = time
for v in range(1, n+1):
if data[u][v] == 0:
continue
if color[v] == 'White':
dfs(v)
color[u] = 'Black'
time += 1
f[u] = time
n = int(input())
A = [list(map(int, input().split()))for ... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,292 |
s184138024 | p02238 | u803657704 | 1548395208 | Python | Python3 | py | Accepted | 20 | 5712 | 503 | N = int(input())
L = [[] for i in range(N+1)]
d = [0] * (N+1)
f = [0] * (N+1)
time = 0
def dfs(key):
global time
time += 1
d[key] = time
for i in range(len(L[key])):
if d[L[key][i]] == 0:
dfs(L[key][i])
time += 1
f[key] = time
for i in range(N):
Q = list(map(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,293 |
s393433782 | p02238 | u137545635 | 1544443925 | Python | Python3 | py | Accepted | 70 | 7404 | 5,051 | #-*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B
"""
import itertools
import time
import logging
def input_from_txt(number=1):
import requests
url = "https://judgedat.u-aizu.ac.jp/testcases/ALDS1_11_B/%s/in" % number
res = requests.get(url)
input = res.text... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,294 |
s502151872 | p02238 | u978863922 | 1544017783 | Python | Python3 | py | Accepted | 20 | 5732 | 1,198 | # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_A&lang=jp
# Graph: python3
# 2018.12.05 yonezawa
import sys
input = sys.stdin.readline
class node:
def __init__(self):
n = self.n = int(input())
self.cnt = 0
self.start = [-1] * n
self.end = [-1] * n
self.... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,295 |
s350796767 | p02238 | u281836941 | 1543815615 | Python | Python3 | py | Accepted | 20 | 5712 | 491 |
n=int(input())
used=[False for i in range(n)]
d=[0 for i in range(n)]
f=[0 for i in range(n)]
mat=[]
for i in range(n):
tmp=list(map(int,input().split()))
mat.append(tmp[2:])
t=1
def dfs(now):
global t
if used[now]:
return
else:
used[now]=True
d[now]=t
t+=1
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
| 29,296 |
s276029753 | p02238 | u800534567 | 1542324135 | Python | Python3 | py | Accepted | 20 | 5800 | 618 | import sys
n = int(sys.stdin.readline())+1
m = [[0] * n for _ in range(n)]
discover_time = [-1] * n
finish_time = [0] * n
clock = -1
def walk(p):
global clock
clock += 1
for i in range(n):
if m[p][i]==0: continue
if discover_time[i]<0:
discover_time[i] = clock
clo... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,297 |
s490230282 | p02238 | u125481461 | 1541777251 | Python | Python3 | py | Accepted | 20 | 5624 | 1,389 | import sys
def push_vertex(frame, vtx, search_queue, outputs, vertices):
#print("frame:{} push:{}".format(frame, vtx))
outputs[vtx] = [frame, None]
search_queue.append(vtx)
[vertices[key].remove(vtx) for key in vertices.keys() if vtx in vertices[key]]
return
def main():
n = int(input())
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,298 |
s287827229 | p02238 | u760378812 | 1539371392 | Python | Python3 | py | Accepted | 30 | 6128 | 997 | def dfs_init(color,n,dq):
for i in range(n):
color[i] = "White"
def next(u):
for v in range(list_next[u],n):
list_next[u] = v+1
if list_m[u][v]:
return v
def dfs_visit(u,color,dq,tt):
tt = tt
dq.append(u)
color[u] = "Gray"
list_d[u] = tt + 1
tt += 1
while dq:
u = dq[-1]
v = next(u)
if v != 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
| 29,299 |
s660499045 | p02238 | u260980560 | 1539301739 | Python | Python3 | py | Accepted | 20 | 5636 | 572 | import sys
readline = sys.stdin.readline
write = sys.stdout.write
N = int(readline())
G = [None]*(N+1)
for i in range(N):
u, k, *vs = map(int, readline().split())
G[u] = vs
begin = [-1]*(N+1)
end = [-1]*(N+1)
lb = iter(range(1, 2*N+1)).__next__
def dfs(v):
begin[v] = lb()
for w in G[v]:
if be... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,300 |
s113220048 | p02238 | u487861672 | 1538874119 | Python | Python3 | py | Accepted | 20 | 5664 | 1,130 | class Node():
def __init__(self, v):
self.d = 0
self.f = 0
self.v = v
def __repr__(self):
return "Node({},{},{})".format(
self.d, self.f, self.v)
def read_node():
n = int(input())
adj_list = [[] for _ in range(n + 1)]
for _ in range(n):
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,301 |
s899996142 | p02238 | u697145890 | 1537971353 | Python | Python3 | py | Accepted | 30 | 6416 | 1,068 | import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
global current_time
global visited,go_time,back_time
global G
def dfs(node_id):
global current_time #書かないとローカル変数扱いされる
go_time[n... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,302 |
s853710587 | p02238 | u629780968 | 1537855919 | Python | Python3 | py | Accepted | 20 | 5660 | 430 | 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
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N):
u, _, *v = map(lambda x:int(x)-1, input().split())
edge[u] = sorted(v)
D, F = [-1] * N, [-1] * N
c = 1
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,303 |
s537118679 | p02238 | u657361950 | 1534247134 | Python | Python3 | py | Accepted | 20 | 5632 | 787 | time = 1
class Vertex:
def __init__(self, u, k):
self.u = u
self.vertices = [0] * k
self.d = self.f = 0
def __str__(self):
return str(self.u) + ' ' + str(self.d) + ' ' + str(self.f)
def DFS(n, vertices):
for i in range(n):
if vertices[i].d == 0:
DFS_(vertices, vertices[i].u)
def DFS_(vertitces, 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,304 |
s608684090 | p02238 | u578148790 | 1533737871 | Python | Python3 | py | Accepted | 20 | 5696 | 1,160 | WHITE = 0
GRAY = 1
BLACK = 2
tt = -1
def next(u, m, n, nt):
start = nt[u]
for v in range(start, n):
nt[u] = v + 1
if m[u][v]:
return v
return -1
def dfs_visit(r, m, n, color, d, f):
nt = [0] * n
stack = [r]
color[r] = GRAY
global tt
tt += 1
d[r] = tt
... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,305 |
s271076357 | p02238 | u269568674 | 1532660776 | Python | Python3 | py | Accepted | 20 | 5660 | 470 | 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]*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,306 |
s400617680 | p02238 | u940395729 | 1532658961 | Python | Python3 | py | Accepted | 20 | 5712 | 476 | def depthFirstSearch(i, Adj, d, f, t):
if d[i - 1]:
return t
d[i - 1] = t
t += 1
for v in Adj[i - 1]:
t = depthFirstSearch(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] *... | p02238 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Depth First Search</H1>
<p... | 4
1 1 2
2 1 4
3 0
4 1 3
| 1 1 8
2 2 7
3 4 5
4 3 6
| 29,307 |
s212234874 | p02238 | u079141094 | 1468219106 | Python | Python3 | py | Accepted | 20 | 7840 | 620 | # Graph I - Depth First Search
def dfs(idx,A):
global time,d,f
d[idx] = time
time += 1
for i,v in enumerate(A[idx]):
if v == 1 and d[i] == 0:
dfs(i,A)
f[idx] = time
time += 1
n = int(input())
A = []
for _ in range(n):
ss = list(map(int, input().split()))
u = ss[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,308 |
s603417613 | p02239 | u255317651 | 1531404651 | Python | Python3 | py | Accepted | 20 | 5632 | 867 | # -*- coding: utf-8 -*-
"""
Created on Sun Jul 8 10:56:33 2018
@author: maezawa
"""
n = int(input())
adj = [[] for _ in range(n)]
d = [-1 for _ in range(n)]
d[0] = 0
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].append(ain[i+2]-1)
... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,309 |
s472090583 | p02239 | u684241248 | 1531482437 | Python | Python3 | py | Accepted | 30 | 6132 | 2,078 | # -*- coding: utf-8 -*-
from collections import deque
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] ... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,310 |
s494801859 | p02239 | u424720817 | 1532054197 | Python | Python3 | py | Accepted | 20 | 5720 | 506 | n = int(input())
graph = [[0 for i in range(n)] for j in range(n)]
d = [0] * n
f = [0] * n
queue = [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
f[0] = 1
while len(queue) != 0:
i = queue.pop(0)
for j in range(n):
... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,311 |
s426466051 | p02239 | u424720817 | 1532060498 | Python | Python3 | py | Accepted | 20 | 5716 | 506 | n = int(input())
graph = [[0 for i in range(n)] for j in range(n)]
d = [0] * n
f = [0] * n
queue = [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
f[0] = 1
while len(queue) != 0:
i = queue.pop(0)
for j in range(n):
... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,312 |
s098794206 | p02239 | u279605379 | 1534732245 | Python | Python3 | py | Accepted | 30 | 6008 | 431 | from collections import deque
n = int(input())
A = [0]*(n+1)
D = [-1]*(n+1)
DP = [0]*(n+1)
d = deque()
for i in range(n):
A[i+1] = [int(i) for i in input().split()]
d.append(1)
D[1] = 0
DP[1] = 1
while(len(d)>0):
tmp = d.pop()
for i in A[tmp][2:]:
if not DP[i]:
D[i] = D[tmp]+1
... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,313 |
s024514501 | p02239 | u726330006 | 1540441018 | Python | Python3 | py | Accepted | 20 | 5712 | 757 | def get_depth(graph,tmp_depth,vertex_list,depth_list):
new_vertex_list=[]
for vertex in vertex_list:
for j in range(len(depth_list)):
if(graph[vertex][j]!=0 and depth_list[j]==-1):
depth_list[j]=tmp_depth + 1
new_vertex_list.append(j)
if(len(new_vertex_lis... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,314 |
s287996781 | p02239 | u094978706 | 1540813653 | Python | Python3 | py | Accepted | 20 | 6012 | 628 | from collections import deque
n = int(input())
adj = [0]*n # adjacent list
d = [-1]*n # distance from the source vertex
c = ['w']*n # the 'color' of each vertex
# receiving input (the structure of the graph)
for i in range(n):
tmp = list(map( int, input().split() ) )
adj[tmp[0]-1] = list(map(lambda x : x - 1... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,315 |
s633390557 | p02239 | u805716376 | 1551369872 | Python | Python3 | py | Accepted | 20 | 5628 | 254 | N= int(input())
E = [input().split()[2:] for _ in [0]*N]
Q = [0]
L = [0] + [-1]*N
while Q:
top = Q.pop(0)
for i in E[top]:
i = int(i) - 1
if L[i] < 0 :L[i] = L[top] +1 ; Q+= [i]
for i in range(N):print(i + 1 ,int(L[i]))
| p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,316 |
s630254507 | p02239 | u805716376 | 1551369947 | Python | Python3 | py | Accepted | 20 | 5624 | 285 | N= int(input())
E = [input().split()[2:] for _ in [0]*N]
Q = [0]
L = [0] + [-1]*N
def func(ide):
global Q
for i in E[ide]:
i = int(i) - 1
if L[i] < 0 :L[i] = L[ide] +1 ;Q += [i]
while Q:top = Q.pop(0);func(top)
for i in range(N):print(i + 1 ,int(L[i]))
| p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,317 |
s093791075 | p02239 | u805716376 | 1551369977 | Python | Python3 | py | Accepted | 20 | 5624 | 288 | N= int(input())
E = [input().split()[2:] for _ in [0]*N]
Q = [0]
L = [0] + [-1]*N
def func(ide):
global Q
for i in E[ide]:
i = int(i) - 1
if L[i] < 0 :L[i] = L[ide] +1 ;Q.append(i)
while Q:top = Q.pop(0);func(top)
for i in range(N):print(i + 1 ,int(L[i]))
| p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,318 |
s315919309 | p02239 | u805716376 | 1551370031 | Python | Python3 | py | Accepted | 20 | 5624 | 291 | N= int(input())
E = [input().split()[2:] for _ in range(N)]
Q = [0]
L = [0] + [-1]*N
def func(ide):
global Q
for i in E[ide]:
i = int(i) - 1
if L[i] < 0 :L[i] = L[ide] +1 ;Q.append(i)
while Q:top = Q.pop(0);func(top)
for i in range(N):print(i + 1 ,int(L[i]))
| p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,319 |
s907654308 | p02239 | u805716376 | 1551370290 | Python | Python3 | py | Accepted | 20 | 5624 | 325 | N= int(input())
E = [input().split()[2:] for _ in range(N)]
Q = [0]
L = [0] + [-1]*N
frag = [1] + [0]*N
def func(ide):
global Q
for i in E[ide]:
i = int(i) - 1
if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i)
while Q:top = Q.pop(0);func(top)
for i in range(N):print(i + 1 ,int(L[i... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,320 |
s743883354 | p02239 | u805716376 | 1551370353 | Python | Python3 | py | Accepted | 20 | 5628 | 330 | N= int(input())
E = [input().split()[2:] for _ in range(N)]
Q = [0]
L = [0] + [-1]*N
frag = [1] + [0]*N
def func(ide):
global Q
for i in E[ide]:
i = int(i) - 1
if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i)
while Q:top = Q[0];func(top);del Q[0]
for i in range(N):print(i + 1 ,in... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,321 |
s101006892 | p02239 | u805716376 | 1551370483 | Python | Python3 | py | Accepted | 20 | 5628 | 330 | N= int(input())
E = [input().split()[2:] for _ in range(N)]
Q = [0]
L = [0] + [-1]*N
frag = [1] + [0]*N
def func(ide):
global Q
for i in E[ide]:
i = int(i) - 1
if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i)
while Q:top = Q[0];func(top);del Q[0]
for i in range(N):print(i + 1 ,in... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,322 |
s649235798 | p02239 | u805716376 | 1551370696 | Python | Python3 | py | Accepted | 20 | 5632 | 348 | N= int(input())
E = [input().split()[2:] for _ in range(N)]
Q = [0]
L = [0] + [-1]*N
frag = [1] + [0]*N
def func(ide):
global Q
for i in E[ide]:
i = int(i) - 1
if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i)
else:pass
while Q:top = Q[0];func(top);del Q[0]
for i in range(... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,323 |
s885769059 | p02239 | u805716376 | 1551371193 | Python | Python3 | py | Accepted | 20 | 5624 | 339 | N= int(input())
E = [input().split()[2:] for _ in range(N)]
Q = [0]
L = [0] + [-1]*N
frag = [1] + [0]*N
def func(ide):
global Q
for i in E[ide]:
i = int(i) - 1
if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i)
while Q:top = Q[0];func(top);del Q[0]
for i in range(N):print(... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,324 |
s327700154 | p02239 | u357267874 | 1555812422 | Python | Python3 | py | Accepted | 40 | 6928 | 524 | from queue import Queue
n = int(input())
A = [[0 for i in range(n)] for j in range(n)]
d = [-1 for i 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
q = Queue()
q.put(0)
d[0] = 0
while not q.empty():
u = q.get()
# print('visite... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,325 |
s041311605 | p02239 | u165578704 | 1556441677 | Python | Python3 | py | Accepted | 30 | 6056 | 702 | # -*- coding: utf-8 -*-
import sys
from collections import deque
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 ra... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,326 |
s764876342 | p02239 | u247705495 | 1556774682 | Python | Python3 | py | Accepted | 30 | 6016 | 946 | from collections import deque
n = int(input())
points = [0 for i in range(n)]
class Point:
def __init__(self, number, arrow):
self.number = number
self.arrow = arrow
self.destination = []
self.distance = -1
self.hadSearched = False
for i in range(n):
L = list(m... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,327 |
s630699570 | p02239 | u821080069 | 1559555430 | Python | Python3 | py | Accepted | 30 | 6040 | 798 | from collections import deque
n = int(input())
graph = [[] for _ in range(n)]
global Q, S, T
global visited, dis
Q = deque([0])
S = [0] #訪れた順
T = []
visited = [0 for _ in range(n)]
dis = [-1 for _ in range(n)] #初めからの距離
visited[0] = 1
dis[0] = 0
def input_graph(n):
for _ in range(n):
node_id, num, *v = list(map(in... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,328 |
s776982097 | p02239 | u567380442 | 1422363571 | Python | Python3 | py | Accepted | 40 | 6728 | 458 | n = int(input())
adj = [list(map(int, input().split()))[2:] for _ in range(n)]
d = [-1] * n
s = 1
q = []
d[s - 1] = 0
q.append(s)
while len(q):
u = q.pop()
v = adj[u - 1]
for vi in v:
if d[vi - 1] == -1:
d[vi - 1] = d[u - 1] + 1
q.append(vi)
elif d[vi - 1] ... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,329 |
s266441137 | p02239 | u809822290 | 1436340928 | Python | Python3 | py | Accepted | 40 | 6768 | 672 | from sys import stdin
X = [ 0 for i in range(100) ]
d = [ 0 for i in range(100) ]
G = [[ 0 for i in range(100) ] for i in range(100)]
queue = [ 0 for i in range(100) ]
t = 0
head = 0
tail = 0
def BFS(i) :
global head
for j in range(n) :
if G[i][j] == 1 and d[j] == -1 :
d[j] = d[i] + 1
queue[head] = j
he... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,330 |
s700990777 | p02239 | u689297737 | 1437200252 | Python | Python | py | Accepted | 20 | 4360 | 2,107 | # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_C
# Breadth 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._... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,331 |
s558674459 | p02239 | u882992966 | 1442933985 | Python | Python3 | py | Accepted | 30 | 7748 | 1,160 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
def bfs(matrix):
distances = [-1 for _ in range(len(matrix))]
queue = [0]
distances[0] = 0
while 0 < len(queue):
node_id = queue.pop(0) # Dequeue
distance = distances[node_id]
for index, candidate in enumerate(matrix[... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,332 |
s271542756 | p02239 | u881590806 | 1450664405 | Python | Python | py | Accepted | 10 | 6472 | 451 | n = int(raw_input())
graph = [[] for i in range(n)]
for i in range(n):
entry = map(int,raw_input().strip().split(' '))
u = entry[0]-1
for v in entry[2:]:
v -= 1
graph[u].append(v)
d = [-1 for i in range(n)]
d[0] = 0
t = 1
q = []
q.append(0)
while len(q) > 0:
u = q[0]
for v in gra... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,333 |
s415676641 | p02239 | u669284080 | 1451226943 | Python | Python3 | py | Accepted | 20 | 7776 | 449 | #!/usr/bin/python3
def find(id, V, d, dist):
i = id - 1
dist[i] = d
for v in V[i]:
if dist[v - 1] == -1 or dist[v - 1] > d + 1:
find(v, V, d + 1, dist)
n = int(input())
# [isFind, d, f]
A = [[False, 0, 0] for i in range(n)]
U = []
V = []
dist = [-1] * n
for i in range(n):
l = l... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,334 |
s503774294 | p02239 | u920118302 | 1454035251 | Python | Python | py | Accepted | 30 | 6540 | 624 | n = int(raw_input())
G = [[0 for i in range(n+1)] for j in range(n+1)]
d = [-1 for i in range(n+1)]
for i in range(n):
v = map(int, raw_input().split())
for j in range(v[1]):
G[v[0]][v[2+j]] = 1
flag = [0 for i in range(n+1)]
tn = [[0 for i in range(n+1)] for j in range(n+1)]
tn[0][1] = 1
r = 0
for i ... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,335 |
s399021939 | p02239 | u069446126 | 1454087168 | Python | Python | py | Accepted | 10 | 6476 | 613 |
def BFS(s = 0):
Q.pop(0)
color[s] = 2
for j in range(len(color)):
if A[s][j] == 1 and color[j] == 0:
Q.append(j)
color[j] = 1
d[j] = d[s] + 1
if len(Q) != 0:
BFS(Q[0])
n = int(raw_input())
A = [0] * n
for i in range(n):
A[i] = [0] * n
for i in r... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,336 |
s269706758 | p02239 | u119456964 | 1454094197 | Python | Python | py | Accepted | 80 | 6472 | 548 | n = int(raw_input())
d = [99999 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
def BFS(s):
for e in range(n):
if M[s][e] == 1:
if d[e] > d[s] + 1:
d[e] = d[s]+1
BFS(e)
for i in range(n):
G = map(int, raw_input(... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,337 |
s255114464 | p02239 | u828153094 | 1454145786 | Python | Python | py | Accepted | 10 | 7036 | 554 | #!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from Queue import Queue
def main():
num = int(stdin.readline())
L = []
for _ in xrange(num):
L.append([int(s) for s in stdin.readline().split()[2:]])
d = [-1] * num
d[0] = 0
q = Queue(100)... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,338 |
s839252610 | p02239 | u797673668 | 1454254058 | Python | Python3 | py | Accepted | 40 | 8068 | 507 | from collections import deque
n = int(input())
g = [None] * n
visited = [0] * n
dist = [-1] * n
queue = deque()
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:]]
n -= 1
queue.append((0, 0))
visited[0] = 1
while queue:
i, d = queu... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,339 |
s856276711 | p02239 | u834416077 | 1454402221 | Python | Python | py | Accepted | 70 | 6416 | 502 | n = int(raw_input())
d = [99999 for i in range(n)]
G = [0 for i in range(n)]
v = [[0 for i in range(n)] for j in range(n)]
def BFS(s):
for e in range(n):
if v[s][e] == 1:
if d[e] > d[s] + 1:
d[e] = d[s]+1
BFS(e)
for i in range(n):
G = map(int, raw_input().split())
for j in range... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,340 |
s727621013 | p02239 | u705265874 | 1454413842 | Python | Python | py | Accepted | 30 | 6488 | 506 | n = int(raw_input())
d = [99999 for i in range(n)]
G = [0 for i in range(n)]
v = [[0 for i in range(n)] for j in range(n)]
def BFS(s):
for e in range(n):
if v[s][e] == 1:
if d[e] > d[s] + 1:
d[e] = d[s]+1
BFS(e)
for i in range(n):
G = map(int, raw_input().split())
for j in ra... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,341 |
s736152043 | p02239 | u705265874 | 1454413877 | Python | Python | py | Accepted | 20 | 6472 | 506 | n = int(raw_input())
d = [99999 for i in range(n)]
G = [0 for i in range(n)]
v = [[0 for i in range(n)] for j in range(n)]
def BFS(s):
for e in range(n):
if v[s][e] == 1:
if d[e] > d[s] + 1:
d[e] = d[s]+1
BFS(e)
for i in range(n):
G = map(int, raw_input().split())
for j in ra... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,342 |
s689398689 | p02239 | u824204304 | 1454414387 | Python | Python | py | Accepted | 20 | 6580 | 524 | n = int(raw_input())
dis = [99999 for i in range(n)]
G = [0 for i in range(n)]
v = [[0 for i in range(n)] for j in range(n)]
def BFS(s):
for e in range(n):
if v[s][e] == 1:
if dis[e] > dis[s] + 1:
dis[e] = dis[s]+1
BFS(e)
for i in range(n):
G = map(int, raw_input().split())
f... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,343 |
s830948929 | p02239 | u393769849 | 1454415986 | Python | Python | py | Accepted | 20 | 6488 | 559 |
n = int(raw_input())
d = [99999 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
def BFS(s):
for e in range(n):
if M[s][e] == 1:
if d[e] > d[s] + 1:
d[e] = d[s]+1
BFS(e)
for i in range(n):
G = map(int, raw_i... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,344 |
s374873684 | p02239 | u334643297 | 1454416483 | Python | Python | py | Accepted | 20 | 6492 | 449 | n = int(raw_input())
d = [100 for i in range(n)]
G = [0 for i in range(n)]
v = [[0 for i in range(n)] for j in range(n)]
def BFS(s):
for e in range(n):
if v[s][e] == 1:
if d[e] > d[s] + 1:
d[e] = d[s]+1
BFS(e)
for i in range(n):
G = map(int, raw_input().split())
for j in range(G[1]):
v[G[0]-1][G[j+2... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,345 |
s801439286 | p02239 | u000228958 | 1454416693 | Python | Python | py | Accepted | 10 | 6416 | 620 | n = input()
d = [-1 for i in xrange(n + 1)]
Q = []
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_map[i][tmp[j + 2]] = 1
color[1] = 'GRAY'
d[1] = 0... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,346 |
s380316314 | p02239 | u563876281 | 1454418160 | Python | Python | py | Accepted | 40 | 6492 | 531 | n = int(raw_input())
d = [100 for i in range(n)]
G = [0 for i in range(n)]
v = [[0 for i in range(n)] for j in range(n)]
def Bread(s):
for e in range(n):
if v[s][e] == 1:
if d[e] > d[s] + 1:
d[e] = d[s]+1
Bread(e)
for i in range(n):
G = map(int, raw_input(... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,347 |
s070755842 | p02239 | u967035362 | 1454419265 | Python | Python | py | Accepted | 40 | 6960 | 444 | from __future__ import print_function
import time
from sys import stdin
from Queue import Queue
start = time.clock()
i = 0
num=int(stdin.readline())
L=[]
for _ in range(num):
L.append([int(s) for s in stdin.readline().split()[2:]])
d=[-1]*num
d[0]=0
q=Queue(100)
q.put(0)
while not q.empty():
u=q.get()
for... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,348 |
s181753197 | p02239 | u038243492 | 1454422902 | Python | Python | py | Accepted | 20 | 6588 | 538 | n = int(raw_input())
d = [100 for i in range(n)]
G = [0 for i in range(n)]
v = [[0 for i in range(n)] for j in range(n)]
def Bread(s):
for e in range(n):
if v[s][e] == 1:
if d[e] > d[s] + 1:
d[e] = d[s]+1
Bread(e)
for i in range(n):
G = map(int, raw_inpu... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,349 |
s334978559 | p02239 | u038005340 | 1454423528 | Python | Python | py | Accepted | 20 | 6476 | 576 | n = int( raw_input() )
d = [ 100 for i in range(n) ]
G = [ 0 for i in range(n) ]
v = [ [ 0 for i in range(n) ] for j in range(n) ]
def BFS(s):
for e in range(n):
if v[ s ][ e ] == 1:
if d[ e ] > d[ s ] + 1:
d[ e ] = d[ s ] + 1
BFS(e)
for i in range(n):
G... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,350 |
s551648501 | p02239 | u970436839 | 1454423668 | Python | Python | py | Accepted | 10 | 6488 | 533 | n = input()
d = [-1 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
color = [0 for i in range(n)]
def BFS(s):
color[0] = 1
q = []
q.append(s)
d[s] = 0
while len(q) != 0:
u = q[0]
q.pop(0)
for v in range(n):
if M[u][v] == 1 and color[v] == 0:
color[v] = 1
... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,351 |
s449067310 | p02239 | u663227983 | 1454424560 | Python | Python | py | Accepted | 20 | 6528 | 550 |
n = input()
d = [99999 for i in range(n)]
G = [0 for i in range(n)]
v = [[0 for i in range(n)] for j in range(n)]
def bfs(u):
for i in range(n):
if v[u][i] == 1:
if d[i] > d[u] + 1:
d[i] = d[u] + 1
bfs(i)
else:
continue
def _():
d[0] = 0
for i in range(n):
bfs(... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,352 |
s095824581 | p02239 | u803327846 | 1454424738 | Python | Python | py | Accepted | 20 | 6492 | 503 | n = int(raw_input())
d = [99999 for i in range(n)]
G = [0 for i in range(n)]
v = [[0 for i in range(n)] for j in range(n)]
def BFS(s):
for e in range(n):
if v[s][e] == 1:
if d[e] > d[s] + 1:
d[e] = d[s]+1
BFS(e)
for i in range(n):
G = map(int, raw_input().split())
for j in... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,353 |
s593790460 | p02239 | u536494052 | 1454425032 | Python | Python | py | Accepted | 10 | 7028 | 554 | #!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from Queue import Queue
def main():
num = int(stdin.readline())
L = []
for _ in xrange(num):
L.append([int(s) for s in stdin.readline().split()[2:]])
d = [-1] * num
d[0] = 0
q = Queue(100)... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,354 |
s495194416 | p02239 | u177808190 | 1454426518 | Python | Python | py | Accepted | 10 | 6552 | 759 | n = int(raw_input())
INF = 10000000
queue = []
def bfs(s):
queue.append(s)
d = [INF for i in range(n)]
d[s] = 0
while len(queue) != 0:
u = queue.pop(0)
for v in range(n):
if M[u][v] == 0:
continue
if d[v] != INF:
continue
... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,355 |
s027851595 | p02239 | u885889402 | 1454430272 | Python | Python3 | py | Accepted | 60 | 7808 | 626 | def breathSerch(P,N):
n=len(P)-1
m=1
QQ=[N[1]]
while(QQ != []):
R=[]
for Q in QQ:
for i in range(1,n+1):
if Q[i]==1 and P[i]==-1:
P[i]=m
R.append(N[i])
QQ = R
m=m+1
n = int(input())
A = [[0 for j in ... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,356 |
s444371776 | p02239 | u253463900 | 1454494828 | Python | Python3 | py | Accepted | 30 | 7792 | 680 | class Node(object):
def __init__(self, V):
self.V = V
self.d = -1
n = int(input())
nodes = [0] * 101
for i in range(n):
data = input().split()
V = list(map(int, data[2:]))
V.sort(reverse = True)
nodes[int(data[0])] = Node(V)
l = [1,]
l_old = []
cnt = 0
while len(l) > 0:
l... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,357 |
s565117701 | p02239 | u341533698 | 1454963343 | Python | Python | py | Accepted | 10 | 6804 | 763 | from collections import deque
n = int(raw_input())
M = [[0]*n for _ in xrange(n)]
color = [0] * n
WHITE = 0
GRAY = 1
BLACK = 2
d = [-1] * n
Q = deque([])
def bfs():
color[0] = GRAY
d[0] = 0
Q.append(0)
while len(Q) > 0:
u = Q.popleft()
for v in xrange(n):
if M[u][v] == 1 an... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,358 |
s841813222 | p02239 | u047737909 | 1455029123 | Python | Python | py | Accepted | 20 | 6492 | 617 | 5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
n = int(raw_input())
d = [99999 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
def BFS(s):
for e in range(n):
if M[s][e] == 1:
if d[e] > d[s] + 1:
d[e] = d[s]+1
... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,359 |
s333329762 | p02239 | u408260374 | 1455858447 | Python | Python3 | py | Accepted | 60 | 8064 | 414 | from collections import deque
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)
dist = [-1] * V
dist[0] = 0
que = deque([0])
while len(que):
v = que.popleft()
for c in edge[v]:
if dist[c] == -1:
... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,360 |
s589296520 | p02239 | u408260374 | 1455858495 | Python | Python3 | py | Accepted | 70 | 8100 | 406 | from collections import deque
V = int(input())
edge = [[] for _ in range(V)]
for _ in range(V):
u, _, *v = map(lambda x: int(x)-1, input().split())
edge[u] = v
dist = [-1] * V
dist[0] = 0
que = deque([0])
while len(que):
v = que.popleft()
for c in edge[v]:
if dist[c] == -1:
dist[c] ... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,361 |
s364870731 | p02239 | u731710433 | 1457254667 | Python | Python3 | py | Accepted | 30 | 8068 | 633 | from collections import deque
def matrix(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
def bfs(v):
d[v] = 1
dist[v] = 0
dq.append(v)
while dq:
v = dq.popleft()
for ... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,362 |
s627058486 | p02239 | u894114233 | 1458908575 | Python | Python | py | Accepted | 10 | 6544 | 620 | def bfs():
while q!=[]:
color[q[0]-1]="grey"
for i in m[q[0]-1]:
if i==0:continue
if color[i-1]=="white":
color[i-1]="grey"
q.append(i)
d[i-1]=d[q[0]-1]+1
del q[0]
n=input()
d=[0]*n
m=[[0]*n for _ in xrange(n)]
info=[0]... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,363 |
s526715484 | p02239 | u567281053 | 1463070941 | Python | Python | py | Accepted | 10 | 6452 | 523 | import sys
def bfs():
global V, D
D[1] = 0
children = V[1]
d = 1
while len(children) != 0 :
new = []
for child in children:
if D[child] == -1:
D[child] = d
new += V[child]
children = new
d += 1
lines = sys.stdin.readlines... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,364 |
s008444005 | p02239 | u072053884 | 1463713219 | Python | Python3 | py | Accepted | 20 | 7756 | 624 | n = int(input())
adj = [None]
for i in range(n):
adj_i = list(map(int, input().split()[2:]))
adj.append(adj_i)
isSearched = [None] + [False] * n
distance = [None] + [-1] * n
def bfs(u):
d = 0
isSearched[u] = True
distance[u] = d
edge = [u]
while edge:
q = list(edge)
edge ... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,365 |
s558584857 | p02239 | u072053884 | 1463737012 | Python | Python3 | py | Accepted | 60 | 8020 | 616 | n = int(input())
adj = [None]
for i in range(n):
adj_i = list(map(int, input().split()[2:]))
adj.append(adj_i)
isSearched = [None] + [False] * n
distance = [None] + [-1] * n
import collections
def bfs(u):
isSearched[u] = True
distance[u] = 0
edge = collections.deque()
edge.append(u)
whi... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,366 |
s852515217 | p02239 | u072053884 | 1463737035 | Python | Python3 | py | Accepted | 40 | 8004 | 616 | n = int(input())
adj = [None]
for i in range(n):
adj_i = list(map(int, input().split()[2:]))
adj.append(adj_i)
isSearched = [None] + [False] * n
distance = [None] + [-1] * n
import collections
def bfs(u):
isSearched[u] = True
distance[u] = 0
edge = collections.deque()
edge.append(u)
whi... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,367 |
s474897395 | p02239 | u569960318 | 1467874961 | Python | Python3 | py | Accepted | 30 | 7748 | 365 | def BFS(G):
ans = [0] + [[i+1,-1] for i in range(len(G))]
def main(G,i,d):
if -1 < ans[i][1] <= d: return
ans[i] = [i, d]
for j in G[i-1][2:]: main(G,j,d+1)
main(G,1,0)
return ans[1:]
if __name__=='__main__':
n = int(input())
G = [list(map(int,input().split())) for _ in... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,368 |
s750202873 | p02239 | u881590806 | 1469460628 | Python | Python | py | Accepted | 20 | 6980 | 836 | import Queue
class Node:
def __init__(self,v):
self.v = v
self.c = []
def bfs(n):
d = {n.v:0}
q = Queue.Queue()
q.put(n)
visited = set([n.v])
while q.qsize() > 0:
x = q.get()
for c in x.c:
if not c.v in visited:
q.put(c)
... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,369 |
s253556017 | p02239 | u984009739 | 1470109604 | Python | Python3 | py | Accepted | 30 | 7760 | 610 | n = int(input())
adj = [None]
for i in range(n):
adji = list(map(int, input().split()[2:]))
adj.append(adji)
isSearched = [None] + [False] * n
distance = [None] + [-1] * n
def BFS(u):
d = 0
isSearched[u] = True
distance[u] = d
edge = [u]
while edge:
q = list(edge)
edge = []... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,370 |
s604640856 | p02239 | u027872723 | 1477217027 | Python | Python3 | py | Accepted | 20 | 7772 | 918 | # -*- coding: utf_8 -*-
level = False
def debug(v):
if level:
print(v)
NOT_FOUND = 0
ENQUEUED = 1
FOUND = 2
def bfs(graph, status, results):
queue = []
queue.append(1)
while len(queue) != 0:
node = queue.pop(0)
status[node] = FOUND
d = results[node]
for edge in... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,371 |
s783015725 | p02239 | u890722286 | 1478336463 | Python | Python3 | py | Accepted | 30 | 8688 | 545 | import queue
n = int(input())
g = {}
for i in range(n):
x = list(map(int, input().split()))
g[x[0]] = [x[2:], 'w', x[0], None]
q = queue.Queue()
node = g[1]
node[-1] = 0
node[1] = 'g'
q.put(node)
while not q.empty():
node = q.get()
d = node[-1] + 1
for i in node[0]:
ch = g[i]
if ... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,372 |
s761242902 | p02239 | u022407960 | 1479656568 | Python | Python3 | py | Accepted | 30 | 8080 | 1,740 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from collections import deque
UNVISITED, VISITED_IN_QUEUE, 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:... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,373 |
s606534938 | p02239 | u022407960 | 1479656792 | Python | Python3 | py | Accepted | 30 | 8132 | 1,740 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from collections import deque
UNVISITED, VISITED_IN_QUEUE, 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:... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,374 |
s029434057 | p02239 | u022407960 | 1479888483 | Python | Python3 | py | Accepted | 30 | 8040 | 1,426 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
4
1 2 2 4
2 1 4
3 0
4 1 3
output:
1 0
2 1
3 2
4 1
"""
import sys
from collections import deque
UNVISITED, VISITED_IN_QUEUE, 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, v_de... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,375 |
s886171800 | p02239 | u022407960 | 1479888905 | Python | Python3 | py | Accepted | 30 | 8020 | 1,418 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
4
1 2 2 4
2 1 4
3 0
4 1 3
output:
1 0
2 1
3 2
4 1
"""
import sys
from collections import deque
UNVISITED, VISITED_IN_QUEUE, 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, v_de... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,376 |
s075644408 | p02239 | u022407960 | 1479889020 | Python | Python3 | py | Accepted | 50 | 8028 | 1,423 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
4
1 2 2 4
2 1 4
3 0
4 1 3
output:
1 0
2 1
3 2
4 1
"""
import sys
from collections import deque
UNVISITED, VISITED_IN_QUEUE, 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, v_de... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,377 |
s761636018 | p02239 | u811733736 | 1481101259 | Python | Python3 | py | Accepted | 30 | 8160 | 2,402 | from collections import deque
from enum import Enum
class Bfs(object):
""" Breadth First Search """
class Status(Enum):
""" ?????????????¨??????¶??? """
white = 1 # ????¨????
gray = 2 # ?¨???????
black = 3 #?¨???????
def __init__(self, data):
num_of_nodes = len(d... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,378 |
s566447565 | p02239 | u159356473 | 1481181649 | Python | Python3 | py | Accepted | 20 | 7616 | 411 | #coding:utf-8
def BFS(i,A,d,dist):
dist[i]=d
for point in A[i]:
if dist[point-1]==-1 or dist[point-1]>d+1:
BFS(point-1,A,d+1,dist)
if __name__=="__main__":
n=int(input())
A=[]
for i in range(n):
A.append(list(map(int,input().split(" ")))[2:])
dist=[-... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,379 |
s039131846 | p02239 | u022407960 | 1481628324 | Python | Python3 | py | Accepted | 30 | 8048 | 1,248 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
4
1 2 2 4
2 1 4
3 0
4 1 3
output:
1 0
2 1
3 2
4 1
"""
import sys
from collections import deque
UNVISITED, VISITED_IN_QUEUE, POPPED_OUT = 0, 1, 2
def graph_bfs(v_init):
queue = deque()
status[v_init] = VISITED_IN_QUEUE
distance[v_init] = 0
qu... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,380 |
s123078200 | p02239 | u022407960 | 1481628366 | Python | Python3 | py | Accepted | 30 | 8044 | 1,248 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
4
1 2 2 4
2 1 4
3 0
4 1 3
output:
1 0
2 1
3 2
4 1
"""
import sys
from collections import deque
UNVISITED, VISITED_IN_QUEUE, POPPED_OUT = 0, 1, 2
def graph_bfs(v_init):
queue = deque()
status[v_init] = VISITED_IN_QUEUE
distance[v_init] = 0
qu... | p02239 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Breadth First Search</H1>
... | 4
1 2 2 4
2 1 4
3 0
4 1 3
| 1 0
2 1
3 2
4 1
| 29,381 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.