<jupyter_start><jupyter_text><jupyter_code>def bfs_al(G, s):
  n = len(G)
  visited = [False]*n
  path = [-1]*n # parent
  queue = [s]
  visited[s] = True

  while queue:
    u = queue.pop(0)
    for v in G[u]:
      if not visited[v]:
        visited[v] = True
        path[v] = u
        queue.append(v)

  return path
%%file 0404a.al
1 4
0 3 5 6
4 5 6
1 7
0 2 6 7
1 2
1 2 4
3 4
import graphviz as gv
G1 = []
with open("0404a.al") as f:
  for line in f:
    if line == "-\n":
      G1.append([])
    else:
      G1.append([int(x) for x in line.split()])

print(G1)
def drawG_al(G, directed=False, path=[]):
  graph = gv.Digraph("felicidad") if directed else gv.Graph("alegria")
  n = len(G)
  added = set()
  for v, u in enumerate(path):
    if u != -1:
      graph.edge(str(u), str(v), dir="forward", penwidth="2", color="orange")
      added.add(f"{u},{v}")
      added.add(f"{v},{u}")
  for u in range(n):
    for v in G[u]:
      if not directed and not f"{u},{v}" in added:  
        added.add(f"{u},{v}")
        added.add(f"{v},{u}")
        graph.edge(str(u), str(v))
      elif directed:
        graph.edge(str(u), str(v))
  return graph
drawG_al(G1)
path = bfs_al(G1, 5)
path
drawG_al(G1, path=path)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18211120064464142, 'fraction_numerical': 0.03384367445608381, 'mean_word_length': 2.652941176470588, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '195422', 'license': 'CC0-1.0', 'n_tokens_mistral': 553, 'n_tokens_neox': 534, 'n_words': 142, 'path': '0404_bfs_adjacency_list.ipynb', 'repo_name': 'lmcanavals/acomplex', 'size': '1241'}