Easy Compare-and-Set | 프로그래밍의 벗 PivotOJ
PivotOJ

Easy Compare-and-Set

시간 제한: 2000ms메모리 제한: 512MB출처: ICPC 2020-2021 Northwestern Russia Regional ContestBOJ 20236

문제

Let us define "Compare-and-Set" operation for a global variable vv. The operation checks if the variable is equal to aa. If that's true, the variable value changes to bb and the operation succeeds. Otherwise, the variable doesn't change and the operation fails. Let us denote the operation as CAS(a,b)\operatorname{CAS}(a,b).

Imagine that you are given a list of such operations CAS(a1,b1),,CAS(an,bn)\operatorname{CAS}(a_1,b_1), \dots, \operatorname{CAS}(a_n,b_n). Also, you are given an initial value for the variable, cc, and a list of wishes w1,wnw_1, \dots w_n, where wiw_i tells whether the operation CAS(ai,bi)\operatorname{CAS}(a_i,b_i) should be successful. Your task is to determine the order of operations execution so that all the wishes are satisfied.

입력

The first line contains two integers nn and cc (1n1051 \le n \le 10^5; 1c1091 \le c \le 10^9) --- the number of operations and the initial value of the variable.

Each of the next nn lines contains three integers ai,bi,wia_i, b_i, w_i (1ai,bi1091 \le a_i, b_i \le 10^9; 0wi10 \le w_i \le 1), denoting CAS(ai,bi)\operatorname{CAS}(a_i, b_i) operation that you wish to be successful if wi=1w_i = 1 and unsuccessful if wi=0w_i = 0. The operations are numbered from 11 to nn in order of input.

출력

If no correct order of operations exists, output a single word "No".

Otherwise, output a word "Yes" followed by nn distinct integers p1,p2,pnp_1, p_2, \ldots p_n (1pin1 \le p_i \le n), meaning that operation p1p_1 should be executed first, then operation p2p_2, and so on. If there are several possible orders, output any of them.

예제

예제 1

입력
4 1
1 2 0
1 2 1
2 3 1
3 4 0
출력
Yes
4 2 1 3

예제 2

입력
3 1
1 2 1
1 2 1
1 2 0
출력
No
코드를 제출하려면 로그인하세요.