Diverse Singing
Time limit2sMemory limit512 MB
Pick a subset of acts so every singer sings at least once and every song is performed, with each language used at most once per singer and per song.
Statement
In the modern world, diversity is a major concern, language diversity in particular. That is why the upcoming talent show will be held in multiple languages. However, making the program both diverse and not boring is a hard problem.
There are singers and songs to be performed. Each singer has several songs in their repertoire, and some of them can be sung in different languages. For a program to be complete, each participant must sing at least one song, and each song must be sung at least once. For a program to be not boring, each participant may use each language at most once, and each song may be sung in each language at most once.
Given the repertoire of each singer, make a complete and not boring program, or determine that it is impossible.
Input
The first line contains three integers , , and : the number of singers, the number of songs, and the number of possible acts, respectively (, ).
Each of the next lines contains three integers , , and (, , ). This means participant can sing song in language .
Output
If it is impossible to make a complete and not boring program, print a single line containing -1.
Otherwise, print the number of songs to be performed, , on the first line. On the second line, print distinct integers between 1 and : the repertoire entries to include in the program. The entries are numbered from 1 in the order they appear in the input, and they may be printed in any order. If there are several valid answers, print any of them.