Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- sys.setrecursionlimit(0x10000000)
- def add(a, b):
- g[a].append(b)
- g[b].append(a)
- def bfs(st):
- q = []
- q.append(st)
- used[st] = True
- while len(q) != 0:
- v = q.pop(0)
- for i in g[v]:
- if not used[i]:
- used[i] = True
- q.append(i)
- parent[i] = v
- d[i] = d[v] + 1
- n = int(input())
- used = [False] * (n + 10)
- parent = [-1] * (n + 10)
- d = [0] * n
- g = []
- for i in range(n):
- g.append([])
- for i in range(n):
- l = list(map(int, input().split()))
- for j in range(i + 1, n):
- if l[j] == 1:
- add(i, j)
- st, en = list(map(int, input().split()))
- bfs(st - 1)
- if not used[st - 1]:
- print(-1)
- else:
- path = []
- v = en - 1
- while v != -1:
- path.append(v + 1)
- v = parent[v]
- print(len(path) - 1)
- print(*reversed(path))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement