C
C
cleerax2020-04-05 16:11:38
Python
cleerax, 2020-04-05 16:11:38

Finding the shortest path in a directed graph with colored vertices and arcs?

There is the following task:

Given a directed graph with N vertices (N < 50). Vertices and arcs are colored with numbers from 1 to M (M < 6).
Two vertices are indicated, in which the player's chips are located, and the final vertex.
Rules for moving pieces: a player can move a piece along an arc if its color matches the color of the vertex
where another piece is located; moves can only be made in the direction of the arcs of the graph;
sequence of moves is optional. The game ends if one of the pieces reaches the final top.
Write a program to find the shortest path to the final vertex, if it exists.

I made a graph through an adjacency matrix, where adjacent vertices with different colors are marked with different numbers. The algorithm for finding the shortest path cannot be done in any way.
Tell me how this can be done in general, or at least throw off some materials where you can find out about something similar, like these two players, colored peaks, etc.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question