Home>

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 [0] [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.

Input
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.

Imprint
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.

Examples
input data
4
0 1 1 0
1 0 1 0
1 1 0 1
0 0 1 0
2
imprint
1 4
2 4

why do you need d, p, inf?

TigerTV.ru2021-02-23 16:21:44

there is also k there ... it looks like a random-style code ...

Jack_oS2021-02-23 16:22:56

K is the desired number of transfers. is in the condition. infinity is in the dijkstra algorithm.

Интик2021-02-23 16:57:38

@Intik I read the condition, but where is the use of these entities in the code?

Jack_oS2021-02-23 17:08:38
Trends