Solved, it turned out this:
n= int (input ()) inf= 1000000000000 a=  for op in range (n): a.append (list (map (int, input (). split ()))) k= int (input ()) for start in range (0, n): color= ['w'] * n d= [inf] * n p= [''] * n q=  q.append (start) for i in range (0, n): if a [q  [i]]== 1: g.append
Here is the task text:
Problem # 112637. Transplants. Vasya decided to travel a little and found out that there are no direct flights between some cities, so will have to fly with transfers. He wondered between which pairs of cities can be flown with exactly K transfers. Write a program which displays all pairs of such cities.
The first line contains the number of cities on the map N (1 ≤ N ≤ 50). The next N lines contain N numbers each, separated by spaces -elements of the adjacency matrix of the graph that describes the scheme of aviation messages. In the last line, enter the number K -the desired number of transfers.
The program must find all pairs of cities between which it is possible to fly exactly with K transfers. Each pair should be displayed on a separate line, the city numbers in the pair are in ascending order. Numbering starts from one. The pairs must be ordered: first, all pairs that start in city 1 in ascending order of the second city number in the pair, etc. If no such pair is found, output the number 0.
0 1 1 0
1 0 1 0
1 1 0 1
0 0 1 0