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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s966601564 | p02239 | u022407960 | 1481628536 | Python | Python3 | py | Accepted | 30 | 8004 | 1,203 | #!/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()
visited[v_init] = VISITED_IN_QUEUE
distance[v_init] = 0
q... | 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,382 |
s768295617 | p02239 | u923668099 | 1486195485 | Python | Python3 | py | Accepted | 80 | 8628 | 859 | import sys
def debug(x, table):
for name, val in table.items():
if x is val:
print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
return None
def bfs(adj, nxt, dis, sumi, kyori):
nnxt = []
for u in nxt:
sumi[u] = True
dis[u] = kyori
for u in nxt:
... | 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,383 |
s569272050 | p02239 | u923668099 | 1486196711 | Python | Python3 | py | Accepted | 30 | 8044 | 860 | import sys
from collections import deque
def debug(x, table):
for name, val in table.items():
if x is val:
print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
return None
def bfs(n, adj):
dis = [-1] * n
visited = [False] * n
nxt = deque([0])
dis[0] = 0
vi... | 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,384 |
s895522531 | p02239 | u112247126 | 1488511851 | Python | Python3 | py | Accepted | 30 | 8052 | 725 | from collections import deque
def bfs(root):
Q = deque()
distance[root] = 0
Q.append(root)
i = root
while len(Q) > 0:
i = Q.popleft()
for v in range(n):
if adjMat[i][v] == 1 and color[v] == 'white':
Q.append(v)
color[v] = 'gray'
... | 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,385 |
s137017012 | p02239 | u462831976 | 1492810466 | Python | Python3 | py | Accepted | 20 | 7748 | 563 | # -*- coding: utf-8 -*-
import sys
import os
import math
N = int(input())
E = []
E.append([])
d = [-1] * (N + 1)
for i in range(N):
lst = list(map(int, input().split()))
nodes = lst[2:]
E.append(nodes)
#print(E)
q = []
q.append(1)
visited = [False] * (N + 1)
d[1] = 0
visited[1] = True
while q:
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,386 |
s945142879 | p02239 | u923668099 | 1495011636 | Python | Python3 | py | Accepted | 30 | 8048 | 649 | import sys
from collections import deque
inf = 1<<30
def solve():
n = int(input())
Adj = [None] * n
for i in range(n):
u, k, *line = [int(i) - 1 for i in input().split()]
Adj[u] = line
d = bfs(n, Adj)
for i, di in enumerate(d, start=1):
if di == inf:
print(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,387 |
s318552307 | p02239 | u089830331 | 1495581425 | Python | Python3 | py | Accepted | 20 | 7676 | 386 | def breadth_first_search(G):
n = len(G)
d = [-1] * (n + 1)
d[1] = 0
queue = [1]
while len(queue) > 0:
v = queue.pop(0)
for c in G[v]:
if d[c] < 0:
d[c] = d[v] + 1
queue.append(c)
for i in range(1, n + 1):
print(i, d[i])
G = {}
for i in range(int(input())):
x = list(map... | 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,388 |
s006836583 | p02239 | u603049633 | 1496490046 | Python | Python3 | py | Accepted | 40 | 8724 | 580 | n = int(input())
Adj = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
u = list(map(int, input().split()))
if u[1] > 0:
for i in u[2: 2 + u[1]]:
Adj[u[0] - 1][i - 1] = 1
color = [0] * n
d = [-1] * n
import queue
Q = queue.Queue()
color[0] = 1
d[0] = 0
Q.put(1)
while not Q.e... | 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,389 |
s197488091 | p02239 | u370086573 | 1497175775 | Python | Python3 | py | Accepted | 30 | 7700 | 521 | def bfs(G, s):
d = {key: -1 for key in G.keys()}
d[s] = 0
Q = [s]
while len(Q) > 0:
u = Q.pop(0)
for v in G[u]:
if d[v] < 0:
d[v] = d[u] + 1
Q.append(v)
return d
if __name__ == '__main__':
G = {}
n = int(input())
for _ in ran... | 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,390 |
s212669039 | p02239 | u371539389 | 1497264321 | Python | Python3 | py | Accepted | 20 | 7692 | 574 | n=int(input())
G=[[0,[],0,-1]]
for i in range(n):
v=[int(j) for j in input().split(" ")]
u=v.pop(0)
k=v.pop(0)
G.append([k,v,0,-1])
distance=0
dis_list=[1]
G[1][3]=0
G[1][2]=1
while len(dis_list)!=0:
distance+=1
dis_list_cash=[]
for i in dis_list:
k=G[i][0]
v=G[i][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,391 |
s475976624 | p02239 | u067677727 | 1498890414 | Python | Python3 | py | Accepted | 20 | 7772 | 631 | 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)
e... | 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,392 |
s216788460 | p02239 | u067677727 | 1498893013 | Python | Python3 | py | Accepted | 20 | 7872 | 1,104 | # -*- coding: utf-8 -*-
def BFS(adj, start):
n = len(adj)
d = [-1] * n
flag = [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,393 |
s955254965 | p02239 | u426534722 | 1499532256 | Python | Python3 | py | Accepted | 30 | 8180 | 586 | from sys import stdin
from collections import deque
n = int(stdin.readline())
M = [[0] * (n + 1) for _ in range(n + 1)]
d = [200] * (n + 1)
def bfs():
d[1] = 0
dq = deque()
dq.append(1)
while len(dq) > 0:
u = dq.popleft()
for v in range(1, n + 1):
if M[u][v] == 0 or d[v] != 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,394 |
s351352193 | p02239 | u426534722 | 1499533047 | Python | Python3 | py | Accepted | 30 | 8080 | 479 | from sys import stdin
from collections import deque
n = int(stdin.readline())
d = [-1] * (n + 1)
def bfs(G):
d[1] = 0
queue = [1]
dq = deque([1])
while len(dq) > 0:
v = dq.popleft()
for c in G[v]:
if d[c] < 0:
d[c] = d[v] + 1
dq.append(c)
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,395 |
s291574536 | p02239 | u426534722 | 1499533495 | Python | Python3 | py | Accepted | 30 | 8056 | 454 | from sys import stdin
from collections import deque
n = int(stdin.readline())
d = [-1] * (n + 1)
def bfs(G):
d[1] = 0
dq = deque([1])
while len(dq) > 0:
v = dq.popleft()
for c in G[v]:
if d[c] < 0:
d[c] = d[v] + 1
dq.append(c)
for i, x in enume... | 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,396 |
s555246397 | p02239 | u426534722 | 1499533601 | Python | Python3 | py | Accepted | 30 | 8072 | 441 | from sys import stdin
from collections import deque
n = int(stdin.readline())
d = [-1] * (n + 1)
def bfs():
d[1] = 0
dq = deque([1])
while len(dq) > 0:
v = dq.popleft()
for c in G[v]:
if d[c] < 0:
d[c] = d[v] + 1
dq.append(c)
for i, x in enumer... | 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,397 |
s601547382 | p02239 | u426534722 | 1499533775 | Python | Python3 | py | Accepted | 30 | 8092 | 446 | from sys import stdin
from collections import deque
n = int(stdin.readline())
d = [-1] * (n + 1)
def bfs():
d[1] = 0
dq = deque([1])
while len(dq) != 0:
v = dq.popleft()
for c in G[v]:
if d[c] != -1 : continue
d[c] = d[v] + 1
dq.append(c)
for i, x in e... | 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,398 |
s215469299 | p02239 | u426534722 | 1499533844 | Python | Python3 | py | Accepted | 30 | 8076 | 428 | from sys import stdin
from collections import deque
n = int(input())
d = [-1] * (n + 1)
def bfs():
d[1] = 0
dq = deque([1])
while len(dq) != 0:
v = dq.popleft()
for c in G[v]:
if d[c] != -1 : continue
d[c] = d[v] + 1
dq.append(c)
for i, x in enumerate(... | 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,399 |
s295989090 | p02239 | u426534722 | 1499534132 | Python | Python3 | py | Accepted | 30 | 8076 | 428 | from sys import stdin
from collections import deque
n = int(input())
d = [-1] * (n + 1)
def bfs():
d[1] = 0
dq = deque([1])
while len(dq) != 0:
v = dq.popleft()
for c in G[v]:
if d[c] != -1 : continue
d[c] = d[v] + 1
dq.append(c)
for i, x in enumerate(... | 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,400 |
s059002332 | p02239 | u426534722 | 1499534575 | Python | Python3 | py | Accepted | 30 | 8080 | 427 | from sys import stdin
from collections import deque
n = int(input())
d = [-1] * (n + 1)
G = [0] + [list(map(int, input().split()[2:])) for _ in range(n)]
def bfs():
d[1] = 0
dq = deque([1])
while len(dq) != 0:
v = dq.popleft()
for c in G[v]:
if d[c] == -1 :
d[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,401 |
s029221059 | p02239 | u426534722 | 1499534646 | Python | Python3 | py | Accepted | 30 | 8108 | 370 | from sys import stdin
from collections import deque
n = int(input())
d = [-1] * (n + 1)
G = [0] + [list(map(int, input().split()[2:])) for _ in range(n)]
d[1] = 0
dq = deque([1])
while len(dq) != 0:
v = dq.popleft()
for c in G[v]:
if d[c] == -1 :
d[c] = d[v] + 1
dq.append(c)
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,402 |
s840515527 | p02239 | u426534722 | 1499534711 | Python | Python3 | py | Accepted | 30 | 8032 | 360 | from sys import stdin
from collections import deque
n = int(input())
d = [-1] * (n + 1)
G = [0] + [list(map(int, input().split()[2:])) for _ in range(n)]
d[1] = 0
dq = deque([1])
while len(dq) != 0:
v = dq.popleft()
for c in G[v]:
if d[c] == -1 :
d[c] = d[v] + 1
dq.append(c)
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,403 |
s458702712 | p02239 | u091533407 | 1500542064 | Python | Python3 | py | Accepted | 30 | 8152 | 702 | from collections import deque
import sys
def bfs():
color[0] = "GRAY"
d[0] = 0
Q.append(0)
while len(Q) != 0:
u = Q.popleft()
for v in range(n):
if M[u][v] and color[v] == "WHITE":
color[v] = "GRAY"
d[v] = d[u] + 1
Q.append(v)... | 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,404 |
s517253666 | p02239 | u735204496 | 1500616879 | Python | Python | py | Accepted | 10 | 6984 | 877 | import sys
import Queue
d_num = int(sys.stdin.readline().strip())
graph_list = []
for _ in range(0, d_num):
array = sys.stdin.readline().strip().split(" ")
if len(array) <= 2:
graph_list.append([])
else:
graph_list.append([int(array[i]) - 1 for i in range(2, len(array))])
result = [0 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,405 |
s397180544 | p02239 | u510829608 | 1502862083 | Python | Python3 | py | Accepted | 30 | 8048 | 609 | from collections import deque
INF = 1e9
def BFS(n, adj):
d = [INF] * N
d[0] = 0
next_v = deque([0]) # ?¬??????????????????????
while next_v:
u = next_v.popleft()
for v in adj[u]:
if d[v] == INF:
d[v] = d[u] + 1
next_v.append(v)
... | 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,406 |
s678427978 | p02239 | u855199458 | 1502979760 | Python | Python3 | py | Accepted | 30 | 8112 | 622 | # -*- coding: utf-8 -*-
from collections import deque
N = int(input())
adj = [[0]*N for _ in range(N)]
unsearched = set(range(1, N))
result = {n:-1 for n in range(N)}
for n in range(N):
inp = list(map(int, input().split()))
for i in inp[2:]:
adj[inp[0]-1][i-1] = 1
que = deque([[0, 0]]) # edge distanc... | 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,407 |
s550270557 | p02239 | u519227872 | 1504450843 | Python | Python3 | py | Accepted | 20 | 8724 | 464 | n = int(input())
graph = {}
d = [-1] * (n+1)
for i in range(n):
t = list(map(int, input().split()))
v = t[0]
k = t[1]
graph[v] = [t[i+2] for i in range(k)]
from queue import Queue
def bfs(s):
d[s] = 0
q=Queue()
q.put(s)
while not q.empty():
v=q.get()
for child in graph[... | 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,408 |
s592710831 | p02239 | u881590806 | 1504614752 | Python | Python3 | py | Accepted | 50 | 7896 | 1,100 | class Queue:
def __init__(self,c):
self.values = [None]*(c+1)
self.s = 0
self.t = 0
def push(self,x):
if self._next(self.s) == self.t:
raise Exception("Overflow")
self.values[self.s] = x
self.s = self._next(self.s)
def pop(self):
if self.s == self.t:
raise Exception("Unde... | 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,409 |
s009791814 | p02239 | u659034691 | 1504656059 | Python | Python3 | py | Accepted | 20 | 7828 | 807 | #Breadth First Search
n=int(input())
V=[]
a=[1]
for i in range(n):
V.append([int(i) for i in input().split()])
a.append(0)
V=sorted(V,key=lambda x:x[0])
print('1 0')
d=1
c=0
w=[0]
p=[]
while c<n and w!=[]:
i=0
y=[]
# print(c)
while c<n and i<len(w):
j=2
while j<2+V[w[i]][1] and 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,410 |
s430704243 | p02239 | u796784914 | 1505548283 | Python | Python | py | Accepted | 20 | 6504 | 649 | def main():
n = input()
A = []
for i in xrange(n):
A.append(map(int,raw_input().split()))
c,d = bfs(n,A)
for i in xrange(n):
if c[i] == -1:
print i+1, -1
else:
print i+1, d[i]
def bfs(n,A):
color = [-1]*n
d = [-1]*n
Q = []
d[0] = 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,411 |
s140886249 | p02239 | u368364462 | 1505783280 | Python | Python | py | Accepted | 10 | 6780 | 608 | from collections import deque
N = input()
d = [float('inf')] * N
m = [[0] * N for i in range(N)]
Q = deque([])
def bfs(s):
Q.append(s)
d[s] = 0
while(len(Q) != 0):
u = Q.popleft()
for v in range(N):
if (m[u][v] and d[v] == float('inf')):
d[v] = d[u] + 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,412 |
s671879413 | p02239 | u368364462 | 1505786571 | Python | Python | py | Accepted | 20 | 6824 | 587 | from collections import deque
N = input()
d = [float('inf')] * N
m = [[] for i in xrange(N)]
Q = deque([])
def bfs(s):
Q.append(s)
d[s] = 0
while(len(Q) != 0):
u = Q.popleft()
for v in m[u]:
if( d[v] == float('inf')):
d[v] = d[u] + 1
Q.append(v)
... | 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,413 |
s467624321 | p02239 | u236679854 | 1506954844 | Python | Python3 | py | Accepted | 50 | 7820 | 430 | n = int(input())
G = []
G.append([])
for i in range(n):
v = list(map(int, input().split()))
G.append(v[2:])
q = []
q.append(1)
checked = [False] * (n + 1)
checked[1] = True
d = [-1] * (n + 1)
d[1] = 0
while q:
current = q.pop(0)
for v in G[current]:
if not checked[v]:
q.append(v)... | 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,414 |
s152592069 | p02239 | u006169802 | 1507091165 | Python | Python3 | py | Accepted | 30 | 8092 | 461 | from sys import stdin
from collections import deque
n = int(stdin.readline())
g = [None] * n
for _ in range(n):
u, _, *cs = [int(s) for s in stdin.readline().split()]
g[u-1] = [c - 1 for c in cs]
ds = [-1] * n
v = [False] * n
v[0] = True
q = deque([(0, 0)])
while len(q):
u, d = q.popleft()
ds[u] = 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,415 |
s788784502 | p02239 | u798803522 | 1509549118 | Python | Python3 | py | Accepted | 30 | 8104 | 599 | from collections import defaultdict
v_num = int(input())
connect = defaultdict(list)
for v in range(v_num):
inp = [int(n) - 1 for n in input().split(" ")]
connect[inp[0]].extend(inp[2:])
answer = [[m + 1, -1] for m in range(v_num)]
queue = [0]
visited = [0 for n in range(v_num)]
visited[0] = 1
time = 0
while 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,416 |
s117244236 | p02239 | u024715419 | 1510909094 | Python | Python3 | py | Accepted | 20 | 7812 | 646 | def bfs(graph, start, result):
visited = {start: None}
unvisited = [start]
while unvisited:
now = unvisited[0]
unvisited = unvisited[1:]
if visited[now] == None:
result[now] = 0
else:
result[now] = result[visited[now]] + 1
for next in graph[now... | 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,417 |
s916412228 | p02239 | u856963614 | 1511781211 | Python | Python3 | py | Accepted | 30 | 8008 | 453 | import collections
n=int(input())
adj=[]
for i in range(n):
adj.append(list(map(int, input().split())))
Q=[]
Q=collections.deque()
Q.append(0)
D=[-1 for i in range(n)]
D[0]=0
while len(Q)>0:
current=Q.popleft()
for dst in range(n):
for i in range(2,len(adj[current])):
if adj[curren... | 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,418 |
s091532781 | p02239 | u424457654 | 1511886789 | Python | Python3 | py | Accepted | 30 | 6084 | 674 | from collections import deque
def bfs(s):
color[s] = 'GRAY'
d[s] = 0
Q.append(0)
while len(Q) != 0:
u = Q.popleft()
for v in range(n):
if M[u][v] and color[v] == 'WHITE':
color[v] = 'GRAY'
d[v] = d[u] + 1
Q.append(v)
col... | 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,419 |
s965393676 | p02239 | u845643816 | 1512131478 | Python | Python3 | py | Accepted | 20 | 5628 | 567 | n = int(input())
a = [[] for i in range(n)]
for i in range(n):
v = list(map(int, input().split()))
u = v[0] - 1
for j in v[2:]:
a[u].append(j-1)
d = [-1] * n
isDiscovered = [False] * n
def bfs(x):
for i in a[x]:
if not isDiscovered[i]:
isDiscovered [i] = True
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,420 |
s952490512 | p02239 | u152085200 | 1518055654 | Python | Python | py | Accepted | 10 | 4700 | 993 | from sys import stdin
def bfs(graph,start,d):
queue = [start]
explored = []
while len(queue) > 0:
node = queue.pop(0)
# print 'node ' + str(node)
if node not in explored:
neighbours = graph[node]
for neighbour in neighbours:
if neighbour not 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,421 |
s542587342 | p02239 | u650712316 | 1518089515 | Python | Python3 | py | Accepted | 30 | 6028 | 509 | #coding: UTF-8
from collections import deque
n = int(input())
link = [[] for i in range(n+1)]
for i in range(n):
r = list(map(int,input().split()))
u = r.pop(0)
k = r.pop(0)
link[u] = r
searched=set()
queue = deque()
d = [-1 for i in range(n+1)]
v = 1
d[v] = 0
queue.append(v)
searched.add(v)
while queue:
v ... | 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,422 |
s860702984 | p02239 | u662418022 | 1518334090 | Python | Python3 | py | Accepted | 30 | 6116 | 822 | # -*- coding: utf-8 -*-
from collections import deque
if __name__ == '__main__':
n = int(input())
M = [[0 for i in range(n)] for j in range(n)]
for _ in range(n):
l = list(map(int, input().split(" ")))
u = l[0]
k = l[1]
if k != 0:
for v in l[2:]:
... | 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,423 |
s910374550 | p02239 | u426534722 | 1519138135 | Python | Python3 | py | Accepted | 30 | 6036 | 479 | from collections import deque
def MAIN():
n = int(input())
li = [[] for _ in range(n + 1)]
ans = [[i, -1] for i in range(n + 1)]
ans[1][1] = 0
for _ in range(n):
u, k, *v = map(int, input().split())
li[u] = v
dp = deque([1])
while dp:
u = dp.popleft()
for v 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,424 |
s136769960 | p02239 | u150984829 | 1520107941 | Python | Python3 | py | Accepted | 40 | 7004 | 232 | import queue
N=int(input())
M=[input().split()[2:]for _ in[0]*N]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while q.qsize()>0:
u=q.get()
for v in M[u]:
v=int(v)-1
if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[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,425 |
s266639711 | p02239 | u150984829 | 1520107944 | Python | Python3 | py | Accepted | 40 | 7008 | 232 | import queue
N=int(input())
M=[input().split()[2:]for _ in[0]*N]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while q.qsize()>0:
u=q.get()
for v in M[u]:
v=int(v)-1
if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[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,426 |
s227219653 | p02239 | u150984829 | 1520107947 | Python | Python3 | py | Accepted | 50 | 7004 | 232 | import queue
N=int(input())
M=[input().split()[2:]for _ in[0]*N]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while q.qsize()>0:
u=q.get()
for v in M[u]:
v=int(v)-1
if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[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,427 |
s807857536 | p02239 | u150984829 | 1520108151 | Python | Python3 | py | Accepted | 40 | 7004 | 241 | import queue
N=int(input())
M=[list(map(int,input().split()[2:]))for _ in[0]*N]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while q.qsize()>0:
u=q.get()
for v in M[u]:
v-=1
if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[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,428 |
s415983120 | p02239 | u150984829 | 1520108154 | Python | Python3 | py | Accepted | 40 | 7004 | 241 | import queue
N=int(input())
M=[list(map(int,input().split()[2:]))for _ in[0]*N]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while q.qsize()>0:
u=q.get()
for v in M[u]:
v-=1
if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[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,429 |
s698046262 | p02239 | u150984829 | 1520108195 | Python | Python3 | py | Accepted | 40 | 6868 | 244 | import queue,sys
N=int(input())
M=[list(map(int,e.split()[2:]))for e in sys.stdin]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while q.qsize()>0:
u=q.get()
for v in M[u]:
v-=1
if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[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,430 |
s677294964 | p02239 | u150984829 | 1520108197 | Python | Python3 | py | Accepted | 50 | 6868 | 244 | import queue,sys
N=int(input())
M=[list(map(int,e.split()[2:]))for e in sys.stdin]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while q.qsize()>0:
u=q.get()
for v in M[u]:
v-=1
if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[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,431 |
s609147594 | p02239 | u150984829 | 1520108294 | Python | Python3 | py | Accepted | 40 | 7004 | 234 | import queue
N=int(input())
M=[input().split()[2:]for _ in[0]*N]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while not q.empty():
u=q.get()
for v in M[u]:
v=int(v)-1
if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[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,432 |
s221916624 | p02239 | u150984829 | 1520108297 | Python | Python3 | py | Accepted | 50 | 7008 | 234 | import queue
N=int(input())
M=[input().split()[2:]for _ in[0]*N]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while not q.empty():
u=q.get()
for v in M[u]:
v=int(v)-1
if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[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,433 |
s037043895 | p02239 | u150984829 | 1520108378 | Python | Python3 | py | Accepted | 40 | 6884 | 280 | import queue
def s():
N=int(input())
M=[input().split()[2:]for _ in[0]*N]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while not q.empty():
u=q.get()
for v in M[u]:
v=int(v)-1
if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[i])
if'__main__'==__name__:s()
| 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,434 |
s095516121 | p02239 | u150984829 | 1520108381 | Python | Python3 | py | Accepted | 40 | 6884 | 280 | import queue
def s():
N=int(input())
M=[input().split()[2:]for _ in[0]*N]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while not q.empty():
u=q.get()
for v in M[u]:
v=int(v)-1
if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[i])
if'__main__'==__name__:s()
| 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,435 |
s803889574 | p02239 | u150984829 | 1520108538 | Python | Python3 | py | Accepted | 20 | 5624 | 189 | N=int(input())
M=[input().split()[2:]for _ in[0]*N]
q=[0]
d=[-1]*N;d[0]=0
while q:
u=q.pop(0)
for v in M[u]:
v=int(v)-1
if d[v]<0:d[v]=d[u]+1;q+=[v]
for i in range(N):print(i+1,d[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,436 |
s964236510 | p02239 | u150984829 | 1520108856 | Python | Python3 | py | Accepted | 20 | 5624 | 186 | N=int(input())
M=[input().split()[2:]for _ in[0]*N]
q=[0]
d=[0]+[-1]*N
while q:
u=q.pop(0)
for v in M[u]:
v=int(v)-1
if d[v]<0:d[v]=d[u]+1;q+=[v]
for i in range(N):print(i+1,d[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,437 |
s864310204 | p02239 | u869924057 | 1520506968 | Python | Python3 | py | Accepted | 30 | 6016 | 989 | from collections import deque
class Vertex:
_id = -1
_children = []
_depth = -1
def __init__(self, i, c):
self._id = i
self._children = c
def getId(self):
return self._id
def getChildren(self):
return self._children
def getDepth(self):
return 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,438 |
s005659724 | p02239 | u779137493 | 1520997645 | Python | Python3 | py | Accepted | 30 | 6052 | 968 | from collections import deque
n = int(input())
adj = [list(map(int, input().split(' '))) for i in range(n)]
class Node:
def __init__(self, id, ck):
self.id = id
self.ck = ck
self.depth = -1
def __str__(self):
return '{} {}'.format(self.id, self.depth)
class Graph:
def __init__(self):
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,439 |
s960436240 | p02239 | u912143677 | 1522292101 | Python | Python3 | py | Accepted | 20 | 6124 | 664 | n = int(input())
m = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
com = list(map(int, input().split()))
for j in range(com[1]):
m[i][com[j+2]-1] = 1
color = ["white" for i in range(n)]
from collections import deque
queue = deque()
d = [-1 for i in range(n)]
def bfs():
color[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,440 |
s444457962 | p02239 | u126478680 | 1525506860 | Python | Python3 | py | Accepted | 40 | 6468 | 1,007 | from collections import deque
from enum import Enum, auto
class Color(Enum):
WHITE = auto()
GRAY = auto()
BLACK = auto()
n = int(input())
d = [0 for i in range(n)]
f = [0 for i in range(n)]
colors = [] # 頂点の訪問状態
A = [[0 for j in range(n)] for i in range(n)] # 隣接行列
queue = deque([])
# 隣接行列の初期化
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,441 |
s372380867 | p02239 | u138546245 | 1526364965 | Python | Python3 | py | Accepted | 30 | 5740 | 3,681 | import abc
class AdjacentGraph:
"""Implementation adjacency-list Graph.
Beware ids are between 1 and size.
"""
def __init__(self, size):
self.size = size
self._nodes = [[0] * (size+1) for _ in range(size+1)]
def set_adj_node(self, id_, adj_id):
self._nodes[id_][adj_id] = 1... | 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,442 |
s761646396 | p02239 | u089116225 | 1528704404 | Python | Python3 | py | Accepted | 20 | 5724 | 638 | n = int(input())
m = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(n):
tmp = [int(x) for x in input().split()]
u = tmp[0]
k = tmp[1]
l = tmp[2:]
for x in l:
m[u-1][x-1] = 1
dl = [float('inf') for _ in range(n)]
dl[0] = 0
q = [0]
while q:
t = q.pop()
tl = m[t]
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,443 |
s089703073 | p02239 | u404682284 | 1528717763 | Python | Python3 | py | Accepted | 20 | 5616 | 634 | import sys
n = int(input())
input_line = [[int(i) for i in str.split()] for str in sys.stdin.read().splitlines()]
for i in range(n):
input_line[i] = [] if len(input_line[i]) == 2 else input_line[i][2:]
is_visit = [False] * n
distance = [0] * n
queue = [1]
while len(queue) != 0:
id = queue.pop(0)
is_visit[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,444 |
s146939435 | p02239 | u368083894 | 1528718923 | Python | Python3 | py | Accepted | 20 | 6048 | 771 | from collections import deque
def bfs(g, source):
n = len(g)
d = [float('inf') for _ in range(n)]
d[0] = 0
queue = deque()
queue.append(0)
while len(queue) > 0:
cur = queue.popleft()
for next in g[cur]:
if d[cur] + 1 < d[next]:
d[next] = d[cur] + 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,445 |
s766684516 | p02239 | u089116225 | 1528879253 | Python | Python3 | py | Accepted | 30 | 5724 | 603 | n = int(input())
m = [[0 for _ in range(n+1)] for _ in range(n+1)]
#mm = [[] for _ in range(n+1)]
for _ in range(n):
tmp = [int(x) for x in input().split()]
u,k,l = tmp[0],tmp[1],tmp[2:]
#mm[u] += tmp[2:]
for x in l:
m[u][x] = 1
dp = [float('inf') for _ in range(n+1)]
dp[1] = 0
queue = [1]
while queue:
t =... | 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,446 |
s864633135 | p02239 | u089116225 | 1528879423 | Python | Python3 | py | Accepted | 20 | 5736 | 722 | n = int(input())
m = [[0 for _ in range(n+1)] for _ in range(n+1)]
mm = [[] for _ in range(n+1)]
for _ in range(n):
tmp = [int(x) for x in input().split()]
u,k,l = tmp[0],tmp[1],tmp[2:]
mm[u] += tmp[2:]
for x in l:
m[u][x] = 1
dp = [float('inf') for _ in range(n+1)]
dp[1] = 0
queue = [1]
'''
while queue:
t... | 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,447 |
s085191454 | p02239 | u089116225 | 1528879544 | Python | Python3 | py | Accepted | 20 | 5632 | 459 | n = int(input())
m = [[] for _ in range(n+1)]
for _ in range(n):
tmp = [int(x) for x in input().split()]
u,k,l = tmp[0],tmp[1],tmp[2:]
m[u] += tmp[2:]
dp = [float('inf') for _ in range(n+1)]
dp[1] = 0
queue = [1]
while queue:
t = queue.pop(0)
for x in m[t]:
if dp[x] > dp[t] + 1:
dp[x] = dp[t] + 1
que... | 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,448 |
s946052184 | p02239 | u318430977 | 1529683896 | Python | Python3 | py | Accepted | 20 | 5616 | 597 | def bfs(adj, s):
n = len(adj)
d = [-1 for _ in range(n)]
c = [0 for _ in range(n)]
d[s] = 0
c[s] = 1
queue = [s]
while len(queue) > 0:
u = queue.pop(0)
for v in adj[u]:
if c[v] == 0:
c[v] = 1
d[v] = d[u] + 1
queue... | 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,449 |
s701368346 | p02239 | u088372268 | 1529733550 | Python | Python3 | py | Accepted | 30 | 6100 | 715 | from collections import deque
n = int(input())
m = [[0 for j in range(n)] for i in range(n)]
color = [0 for i in range(n)]
q = deque()
dist = [-1 for i in range(n)]
def bfs(s):
color[s], dist[s] = 1, 0
q.append(s)
while len(q) != 0:
u = q.popleft()
for v in range(n):
if m[u][... | 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,450 |
s614703991 | p02239 | u007270338 | 1530196003 | Python | Python3 | py | Accepted | 20 | 5736 | 683 | #coding:utf-8
n = int(input())
Q = [1]
M = [[False for i in range(n)] for j in range(n)]
dataList = []
for i in range(n):
data = list(map(int,input().split()))
dataList.append(data)
for j in range(data[1]):
v = data[j+2] - 1
M[i][v] = True
color = ["white" for i in range(n)]
d = [-1 for i 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,451 |
s199405251 | p02239 | u912237403 | 1375435188 | Python | Python | py | Accepted | 20 | 4276 | 738 | import sys
global status, d
status = {}
d=0
def bfs(keys, GRAPH, depth=0):
global status
if depth>10: quit
buf =[]
for e in keys:
if status[e]==-1:
status[e]=depth
for e2 in GRAPH[e]:
try:
if status[e2] == -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,452 |
s804668414 | p02239 | u782850731 | 1380698247 | Python | Python | py | Accepted | 20 | 4872 | 547 | #!/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,453 |
s405322556 | p02239 | u140201022 | 1389448623 | Python | Python | py | Accepted | 20 | 4840 | 488 | #!/usr/bin/env python
# -*- coding:utf-8 -*-
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... | 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,454 |
s910596783 | p02239 | u327396500 | 1597763340 | Python | Python3 | py | Accepted | 30 | 6076 | 711 | from collections import deque
import sys
input = sys.stdin.readline
n = int(input())
graph = {i: deque() for i in range(1, n+1)}
for i in range(n):
u, k, *v = map(int, input().split())
v.sort()
for vi in v:
graph[u].append(vi)
seen = [0]*(n+1)
queue = deque()
dist = [-1]*(n+1)
def bfs(v):
dis... | 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,455 |
s244124213 | p02239 | u754923116 | 1597623165 | Python | Python3 | py | Accepted | 30 | 6036 | 854 | import collections
def breadth_first_search(g,check,length):
q = collections.deque()
q.append(1)
check[1] = 1
length[1] = 0
while len(q) != 0:
v = q.popleft()
for u in g[v]:
if check[u] == 0:
check[u] = 1
length[u] = length[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,456 |
s524730020 | p02239 | u880802684 | 1597380419 | Python | Python3 | py | Accepted | 30 | 6036 | 579 | # https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/11/ALDS1_11_C
from collections import deque
n = int(input())
graph = {}
res = [-1 for i in range(n + 1)]
for i in range(1, n + 1):
data = input().split()
graph[i] = [int(i) for i in data[2:]]
visited = set()
q = deque()
q.append((1, 0)) # node,dista... | 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,457 |
s352808009 | p02239 | u571995157 | 1597141981 | Python | Python3 | py | Accepted | 20 | 6044 | 730 | from collections import deque
n = int(input())
graph = [[] for _ in range(n + 1)]
for _ in range(n):
input_list = list(map(int, input().split()))
index = input_list[0]
num = input_list[1]
if num >= 1:
nodes = input_list[2:]
for node in nodes:
graph[index].append(node)
... | 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,458 |
s511837907 | p02239 | u849721539 | 1597045053 | Python | Python3 | py | Accepted | 20 | 5628 | 481 | N=int(input())
List = [[] for i in range(N+1)]
for i in range(N):
l=list(map(int,input().split()))
List[l[0]]=l[2:]
#print(List)
D=[10**9 for i in range(N+1)]
Q=[[0,1]]
for i in range(10**9):
if len(Q)==i:
break
if D[Q[i][1]]==10**9:
D[Q[i][1]]=Q[i][0]
for j in List[Q[i][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,459 |
s874211922 | p02239 | u793520502 | 1597042766 | Python | Python3 | py | Accepted | 30 | 6112 | 646 | import sys
input = sys.stdin.readline
from collections import deque
def getNeighbor(A, i):
a = len(A)
for k in range(2, a):
M[i][A[k]-1] = 1
def bfs():
u = q.popleft()
c[u] = 1
for v in range(n):
if M[u][v] and c[v] == 0:
q.append(v)
d[v] = d[u] + 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,460 |
s731813807 | p02239 | u389047838 | 1596983146 | Python | Python3 | py | Accepted | 30 | 6084 | 1,093 | import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return 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,461 |
s359122265 | p02239 | u580036688 | 1596974790 | Python | Python3 | py | Accepted | 30 | 6044 | 507 | from collections import deque
N = int(input())
graph = {i:[] for i in range(N)}
for i in range(N):
g = list(map(int, input().split()))
for j in range(g[1]):
graph[g[0]-1].append(g[j+2]-1)
que = deque()
dist = [-1 for _ in range(N)]
que.append(0)
dist[0] = 0
while que:
top = que.popleft()... | 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,462 |
s118206441 | p02239 | u914515588 | 1596952359 | Python | Python3 | py | Accepted | 50 | 7196 | 1,440 | import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = ... | 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,463 |
s737193224 | p02239 | u204119336 | 1596278481 | Python | Python3 | py | Accepted | 20 | 6032 | 506 | from collections import deque
import sys
sys.setrecursionlimit(1000000)
N=int(input())
graph = [[] for _ in range(N)] # 隣接リスト
for _ in range(N):
v,c,*l = map(int,input().split())
for i in l:
graph[v-1].append(i-1)
# graph[i-1].append(v-1)
dist=[-1]*N
dist[0]=0
d=deque()
d.append(0)
while 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,464 |
s860636202 | p02239 | u439569116 | 1596262143 | Python | Python3 | py | Accepted | 30 | 6052 | 468 | from collections import deque
n = int(input())
li = [list(map(int, input().split())) for _ in range(n)]
graph = [[] for _ in range(n+1)]
for u, k, *v in li:
for i in v:
graph[u].append(i)
ans = [-1] * (n+1)
ans[1] = 0
stack = deque([1])
while stack:
num = stack.popleft()
for s in graph[num]:
... | 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,465 |
s999206443 | p02239 | u537758214 | 1596244014 | Python | Python3 | py | Accepted | 30 | 6036 | 695 | INF = 10**18 + 7
def main():
from collections import deque
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N):
u, k, *A = (int(i)-1 for i in input().split())
G[u] = A
def bfs(s=0):
que = deque([])
dist = [INF]*N
dist[s] = 0
que.append(s)
... | 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,466 |
s997614261 | p02239 | u475852926 | 1596110219 | Python | Python3 | py | Accepted | 40 | 6884 | 496 | import queue
n = int(input())
Graph = [[x-1 for x in list(map(int, input().split()))[2:]] for i in range(n)]
# for i in range(n):
# li = list(map(int, input().split()))
# a = li[0]
# a-=1
# b = li[2:]
# Graph[a].append(b)
dist = [-1]*n
q = queue.Queue()
dist[0] = 0
q.put(0)
while not q.empty... | 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,467 |
s445859460 | p02239 | u222972395 | 1595946745 | Python | Python3 | py | Accepted | 30 | 6040 | 405 | from collections import deque
n = int(input())
graph = [list(map(int,input().split()))[2:] for _ in range(n)]
dist = [-1]*(n+1)
dist[0] = 0
dist[1] = 0
d = deque()
d.append(1)
while d:
v = d.popleft()-1
if len(graph[v]) >= 1:
for i in graph[v]:
if dist[i] == -1:
dist[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,468 |
s244811172 | p02239 | u258473357 | 1595917022 | Python | Python3 | py | Accepted | 40 | 6852 | 1,064 | # coding: utf-8
from queue import Queue
N = int(input())
graph = [None]
for _ in range(N):
graph.append(list(map(int, input().split(" ")))[1:])
class BFSSolver:
def __init__(self, graph):
self.graph = graph
self.queue = Queue()
self.queue.put(1)
self.before_id = 1
sel... | 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,469 |
s479526538 | p02239 | u491421284 | 1595665916 | Python | Python3 | py | Accepted | 20 | 5620 | 992 | n = int(input())
class Node:
def __init__(self, idd, neighbors):
self.idd = idd
self.neighbors = neighbors
self.dist = -1
def __repr__(self):
return "{0} {1}".format(self.idd, self.dist)
def breadthFirstSearch(Nodes):
stack = [Nodes[0]]
Nodes[0].dist = 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,470 |
s961293007 | p02239 | u525205447 | 1595417484 | Python | Python3 | py | Accepted | 20 | 6032 | 370 | import sys
input = sys.stdin.readline
from collections import deque
N = int(input())
G = [list(map(lambda x: int(x)-1, input().split()))[2:] for _ in range(N)]
D = [-1]*N
q = deque([[0, 0]])
while q:
cur, dis = q.popleft()
if D[cur] != -1: continue
D[cur] = dis
for nex in G[cur]:
q.append([nex... | 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,471 |
s091260655 | p02239 | u777962369 | 1595406418 | Python | Python3 | py | Accepted | 30 | 6036 | 369 | from collections import deque
N = int(input())
edge = [[] for _ in range(N+1)]
for i in range(N):
A = list(map(int, input().split()))
edge[A[0]] = A[2:]
ans = [-1]*N
ans[0] = 0
d = deque([[1,0]])
while len(d)>0:
v,dist = d.popleft()
for w in edge[v]:
if ans[w-1]==-1:
ans[w-1]=dist+1
d.append([w... | 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,472 |
s366306369 | p02239 | u562030778 | 1595397467 | Python | Python3 | py | Accepted | 30 | 6036 | 507 | #AC
from collections import deque
n=int(input())
G=[[]]
for i in range(n):
G.append(list(map(int,input().split()))[2:])
#bfs(木でないかも)
L=[-1]*(n+1)
q=deque()
L[1]=0
q.append(1)
while q:
now=q.popleft()
L.append(now)
for next in G[now]:
#探索済み
if L[next]>=0:
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,473 |
s471576839 | p02239 | u842787189 | 1595385933 | Python | Python3 | py | Accepted | 20 | 5624 | 505 | n = int(input())
G = {i:[] for i in range(1, n+1)}
for _ in range(n):
ukv = list(map(int, input().split()))
u = ukv[0]
k = ukv[1]
for i in range(2, 2+k):
G[u].append(ukv[i])
stack = [1]
dist = [-1]*(n+1)
dist[1] = 0
while stack:
target = stack.pop(0)
for target_i in G[target]:
... | 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,474 |
s013813634 | p02239 | u820092408 | 1595253774 | Python | Python3 | py | Accepted | 20 | 6032 | 432 | from collections import deque
n = int(input())
adj = [[]]
for i in range(n):
adj.append(list(map(int, input().split()))[2:])
ans = [-1]*(n+1)
ans[1] = 0
q = deque([1])
visited = [False] * (n+1)
visited[1] = True
while q:
x = q.popleft()
for y in adj[x]:
if visited[y] == False:
q.appe... | 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,475 |
s070330875 | p02239 | u048101135 | 1595164133 | Python | Python3 | py | Accepted | 30 | 6036 | 443 | from collections import deque
n = int(input())
d = [-1]*n
d[0] = 0
M = []
for i in range(n):
adj = list(map(int,input().split()))
if adj[1] == 0:
M += [[]]
else:
M += [adj[2:]]
Q = deque([0])
while Q != deque([]):
u = Q.popleft()
for i in range(len(M[u])):
v = M[u][i]-1
if d[v] ... | 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,476 |
s263840652 | p02239 | u434132766 | 1595095175 | Python | Python3 | py | Accepted | 30 | 6032 | 482 | from collections import deque
N = int(input())
Graph = {}
Node = []
visited = [-1]*(N)
for i in range(N):
tmp = input().split()
if int(tmp[1]) != 0:
Graph[i] = [int(x)-1 for x in tmp[2:]]
else:
Graph[i] = []
queue = deque([0])
visited[0] = 0
while queue:
x = queue.popleft()
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,477 |
s331676298 | p02239 | u864060739 | 1594963322 | Python | Python3 | py | Accepted | 30 | 6032 | 610 | from collections import deque
from sys import stdin
input = stdin.readline
N = int(input())
neighborlist = [None for _ in range(N+1)]
for _ in range(1, N+1):
node, _, *L = list(map(int, input().split()))
neighborlist[node] = L
distancelist = [-1]*(N+1)
queue = deque()
queue.append(1)
distancelist[1] = 0
while... | 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,478 |
s610759793 | p02239 | u069030680 | 1594805265 | Python | Python3 | py | Accepted | 30 | 6008 | 499 | from collections import defaultdict, deque
N = int(input())
edges = {}
scores = defaultdict(lambda: -1)
for _ in range(N):
l = list(map(int, input().split()))
node = l[0]
degree = l[1]
edges[node] = l[2:]
q = deque()
q.append((1, 0))
while q:
node, score = q.popleft()
if scores[node] != -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,479 |
s426897669 | p02239 | u108855621 | 1594755422 | Python | Python3 | py | Accepted | 40 | 6996 | 635 | import sys
from collections import defaultdict
from queue import Queue
def main():
input = sys.stdin.buffer.readline
n = int(input())
g = defaultdict(list)
for i in range(n):
line = list(map(int, input().split()))
if line[1] > 0:
g[line[0]] = line[2:]
q = Queue()
q.... | 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,480 |
s272578820 | p02239 | u879371540 | 1594649721 | Python | Python3 | py | Accepted | 30 | 6028 | 429 | from collections import deque
def bfs(x):
for v in graph[x]:
if dist[v] != -1:
continue
dist[v] = dist[x] + 1
queue.append(v)
if len(queue) == 0:
return
bfs(queue.popleft())
N = int(input())
graph = []
for _ in range(N):
graph.append(list(map(lambda x: int(x)-1, input().split()))[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,481 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.