405912: GYM102156 C Diverse Singing

Memory Limit:0 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Diverse Singingtime limit per test2 secondsmemory limit per test512 mebibytesinputstandard inputoutputstandard output

In the modern world, diversity is the major concern, language diversity in particular. That's why the upcoming talent show is going to be held in multiple languages. However, making the program both diverse and not boring is a tough problem.

There are $$$n$$$ singers going to participate in the show and $$$m$$$ songs to be performed. Each singer has several songs in their repertoire, and some of them may be sung in different languages. For a program to be complete, each participant should sing at least one song and each song should be sung at least once. For a program to be not boring, each participant should use each language no more than once, and each song should be sung in each language no more than once as well.

Given the repertoire of each singer, make a complete and not boring program of the show, or determine that it is impossible.

Input

In the first line of input, there are three integers $$$n$$$, $$$m$$$, $$$k$$$: the number of singers, songs and possible acts, respectively ($$$1 \leq n, m \leq 1000$$$, $$$1 \leq k \leq 10\,000$$$).

The next $$$k$$$ lines describe the repertoires. The $$$i$$$-th line contains three integers $$$p_i$$$, $$$s_i$$$, $$$l_i$$$ ($$$1 \leq p_i \leq n$$$, $$$1 \leq s_i \leq m$$$, $$$1 \leq l_i \leq k$$$) denoting that the participant $$$p_i$$$ can sing the song $$$s_i$$$ in the language $$$l_i$$$.

Output

If it is impossible to make a complete and not boring program, print a single number "-1" (without quotes).

Otherwise, on the first line, print an integer $$$t$$$: the number of songs to be performed. On the second line, print $$$t$$$ distinct integers between $$$1$$$ and $$$k$$$: the repertoire entries to include in the program. The entries are numbered from $$$1$$$ in the order they are given in the input. The repertoire entries can be printed in any order. If there are several possible answers, print any one of them.

ExamplesInput
2 2 4
1 1 1
1 2 1
1 2 2
2 2 2
Output
2
1 4 
Input
2 3 5
1 1 1
1 2 1
2 2 2
2 3 2
2 2 3
Output
3
1 4 5 
Input
2 3 4
1 1 1
1 2 1
2 2 2
2 3 2
Output
-1

加入题单

算法标签: