redblue

Problem Description

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.

Input

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.

Output

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.

Limits

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.

Sample Input 1

3 3
0 1 0
0 2 1
1 2 0

Sample Output 1

YES
0 1

Sample Input 2

5 6
0 0 0
0 1 1
0 2 0
0 3 1
0 4 1
1 1 0

Sample Output 2

NO


Submitting .cpp to 'redblue'


You're not logged in! Click here to login

Time Limit: 1 Seconds
Memory Limit: 1024MB
Your best score: 0
Source: Dunjudge Archive

Subtask Score
1 29
2 30
3 41
4 0