There are a total of N towns, connected by a total of R roads. Each road i connects cities Ai and Bi, and is either coloured red or blue. If the road is coloured red, Ci = 0, and otherwise Ci = 1. It is guaranteed that it is possible to travel between any two towns using only these roads.
The mayor, wanting to save money, has decided to close some of these roads, keeping only N - 1 roads. It must still be possible to travel between any two towns using open roads, and to preserve the scenic beauty of the city, there must be an equal number of red roads and blue roads remaining. Help the mayor decide if this is possible, and if so, construct a possible set of roads to keep such that the above conditions are fulfilled.
The first line of input will contain two integers, N and R.
The next R lines of input will contain three integers each, Ai, Bi and Ci.
The first line of output should contain a string, 'YES' or 'NO', indicating whether it is possible to construct a subset of roads to keep to fulfill the mayor's conditions.
If it is possible, the second line of output should contain a space-seperated list of integers, listing the IDs of the roads to keep. The roads are numbered from 0 to R - 1 in the order of input.
For all subtasks: 0 ≤ Ai, Bi < N, 0 ≤ Ci ≤ 1.
Subtask 1 (29%): 2 ≤ N = R ≤ 1000.
Subtask 2 (30%): 2 ≤ N ≤ 1000, 1 ≤ R ≤ 2500.
Subtask 3 (41%): 2 ≤ N ≤ 2000, 1 ≤ R ≤ 500000.
Subtask 4 (0%): Sample Testcases.
3 3 0 1 0 0 2 1 1 2 0
YES 0 1
5 6 0 0 0 0 1 1 0 2 0 0 3 1 0 4 1 1 1 0
NO
Subtask | Score |
---|---|
1 | 29 |
2 | 30 |
3 | 41 |
4 | 0 |