Tour

시간 제한2초메모리 제한2048 MB

요약
각 간선에 색이 붙은 유향 다중 그래프에서 연속한 두 간선의 색이 다른 닫힌 보행을 m개 이하의 간선으로 찾는다.
난이도

어려움10점 중 8점

유형
그래프, DFS, 구현
정답자
아직 제출이 없습니다

문제

There are many tourist attractions in Toruń. Our tour guides prepared a list of mm one-way walks connecting nn meeting points in the city center. The walks are numbered from 11 to mm and similarly the meeting points are numbered from 11 to nn. Each walk leads from one meeting point to another and allows the participants to see a single attraction on the way. It might be possible to see the same attraction on different walks and there might be mutliple walks between the same pair of meeting points. We would like to organise an interesting tour on our day off.

A tour is a sequence of walks, such that every walk starts at the meeting point where the previous one ends. Furthermore, the last walk ends at the meeting point where the very first walk begins.

We call such a tour interesting if it doesn’t contain the same attraction twice in a row. In other words, every two consecutive walks from the tour allow us to see different attractions, and additionally the very first and very last walks from the tour allow us to see different attractions as well. Note that we do not mind if some non-consecutive walks allow us to see the same attraction. In particular, the same walk might be used multiple times on the tour (but not twice in a row).

Your task is to check if it is possible to form an interesting tour, and if so to find one. You can output any interesting tour that consists of at most mm walks. It can be proven that if there exists an interesting tour, then there exists one consisting of at most mm walks.

입력

The first line contains a positive integer tt (1≤t≤5⋅1051 ≤ t ≤ 5 \cdot 10^5) denoting the number of test cases.

The first line of each test case contains positive integers nn and mm (2≤n2 ≤ n, 1≤m1 ≤ m) denoting the number of meeting points and walks, respectively.

Each of the subsequent mm lines describes one of the mm walks. The ii-th line contains three positive integers x_ix\_i, y_iy\_i and c_ic\_i (1≤x_i,y_i≤n1 ≤ x\_i , y\_i ≤ n, x_i≠y_ix\_i \ne y\_i, 1≤c_i≤m1 ≤ c\_i ≤ m), which indicate that the ii-th walk starts at the meeting point x_ix\_i, ends at the meeting point y_iy\_i, and allows us to see the attraction c_ic\_i.

Let NN and MM denote the sum of nn and mm, respectively, over all test cases. You can assume that N,M≤106N, M ≤ 10^6.

출력

For each test case, in the first line you should output YES if it is possible to organise an interesting tour and NO otherwise. In the former case, the second line should first contain a positive integer kk (2≤k≤m2 ≤ k ≤ m) denoting the number of walks forming the interesting tour. This should be followed by kk integers p_1,p_2,…,p_kp\_1, p\_2, \dots , p\_k separated by single spaces. These numbers should describe an interesting tour, where we first follow walk p_1p\_1, then p_2p\_2, and so on, and finally we follow walk p_kp\_k returning to the original meeting point.

힌트

Illustration of the 4th test case from the example. The arrows represent the walks between meeting points.

예제1

  1. 예제 1

    입력
    5
    3 3
    1 2 1
    2 3 2
    3 1 1
    3 3
    2 1 1
    1 3 3
    3 1 2
    2 2
    1 2 2
    1 2 1
    5 6
    1 2 1
    2 3 2
    3 1 1
    1 4 3
    4 5 4
    5 1 3
    4 4
    1 3 4
    3 2 1
    2 3 2
    2 3 2
    
    예상 출력
    NO
    YES
    2 2 3
    NO
    YES
    6 3 4 5 6 1 2
    YES
    4 2 4 2 3