CF BUDDY
← Problems·

1187C · Vasya And Array

1800 · constructive algorithms, greedy, implementation

Problem: Vasya has an array a1,a2,,ana_1, a_2, \dots, a_n.

You don't know this array, but he told you mm facts about this array. The ii-th fact is a triple of numbers tit_i, lil_i and rir_i (0ti1,1li<rin0 \le t_i \le 1, 1 \le l_i < r_i \le n) and it means:

  • if ti=1t_i=1 then subbarray ali,ali+1,,aria_{l_i}, a_{l_i + 1}, \dots, a_{r_i} is sorted in non-decreasing order;
  • if ti=0t_i=0 then subbarray ali,ali+1,,aria_{l_i}, a_{l_i + 1}, \dots, a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter.

For example if a=[2,1,1,3,2]a = [2, 1, 1, 3, 2] then he could give you three facts: t1=1,l1=2,r1=4t_1=1, l_1=2, r_1=4 (the subarray [a2,a3,a4]=[1,1,3][a_2, a_3, a_4] = [1, 1, 3] is sorted), t2=0,l2=4,r2=5t_2=0, l_2=4, r_2=5 (the subarray [a4,a5]=[3,2][a_4, a_5] = [3, 2] is not sorted), and t3=0,l3=3,r3=5t_3=0, l_3=3, r_3=5 (the subarray [a3,a5]=[1,3,2][a_3, a_5] = [1, 3, 2] is not sorted).

You don't know the array aa. Find any array which satisfies all the given facts.

Input Format: The first line contains two integers nn and mm (2n1000,1m10002 \le n \le 1000, 1 \le m \le 1000).

Each of the next mm lines contains three integers tit_i, lil_i and rir_i (0ti1,1li<rin0 \le t_i \le 1, 1 \le l_i < r_i \le n).

If ti=1t_i = 1 then subbarray ali,ali+1,,aria_{l_i}, a_{l_i + 1}, \dots , a_{r_i} is sorted. Otherwise (if ti=0t_i = 0) subbarray ali,ali+1,,aria_{l_i}, a_{l_i + 1}, \dots , a_{r_i} is not sorted.

Output Format: If there is no array that satisfies these facts in only line print NO (in any letter case).

If there is a solution, print YES (in any letter case). In second line print nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1091 \le a_i \le 10^9) — the array aa, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them.

Sample Cases

Case 1

Input

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

Output

YES
1 2 2 3 5 4 4

Case 2

Input

4 2
1 1 4
0 2 3

Output

NO

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback