Loading environment...
You are curating a custom music playlist that starts with one specific track and ends with another. You have a list of songs, each associated with a set of genres. You must select a sequence of songs, starting from a given start song and ending at a given target song, such that any consecutive pair of songs in the sequence shares at least two genres. Your task is to find any valid path that satisfies these constraints. If multiple valid paths exist, any one is acceptable. If no such path exists, report that it is impossible.
You are given:
The first line contains two strings, S and T:
The second line contains two integers N and G:
The next N lines each describe a song:
If it is possible to reach the target song starting from the start song by following the valid transitions, print the number of songs in the path, followed by each song name in the order they should be played.
If there is no such path, print -1.
Constraints:
(each song can have between 1 and G genres, inclusive)
Song names and genre names are reasonably short strings (e.g., length ≤ 20).
The start and target songs are guaranteed to appear in the list of songs.
SongASongDSongXSongYGraph Construction:
No valid path exists between SongX and SongY.
No comments yet. Be the first to comment!