Hidden Sequence

All submissions for this problem are available.
### Read problems statements in [Hindi](http://www.codechef.com/download/translated/COOK111/hindi/HDDN.pdf), [Mandarin Chinese](http://www.codechef.com/download/translated/COOK111/mandarin/HDDN.pdf), [Russian](http://www.codechef.com/download/translated/COOK111/russian/HDDN.pdf), [Vietnamese](http://www.codechef.com/download/translated/COOK111/vietnamese/HDDN.pdf), and [Bengali](http://www.codechef.com/download/translated/COOK111/bengali/HDDN.pdf) as well. It's not always easy to make up stories around problems ― like this one. We know that there is a hidden sequence $A_1, A_2, \ldots, A_N$ which contains only integers between $1$ and $K$ inclusive. We have acquired $M$ triplets $(X_1, Y_1, Z_1), (X_2, Y_2, Z_2), \ldots, (X_M, Y_M, Z_M)$. A very reliable source has given us intel that for each valid $i$, the $Y_i$th occurrence of the integer $X_i$ in the sequence $A$ is $A_{Z_i}$, i.e. $A_{Z_i} = X_i$ and there are $Y_i1$ indices $j \lt Z_i$ such that $A_j = X_i$. Find any sequence $A$ consistent with this information or determine that no such sequence exists. ### Input  The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.  The first line of each test case contains three spaceseparated integers $N$, $K$ and $M$.  $M$ lines follow. For each $i$ ($1 \le i \le M$), the $i$th of these lines contains three spaceseparated integers $X_i, Y_i$ and $Z_i$. ### Output For each test case:  If no valid sequence exists, print a single line containing the string `"No"`.  Otherwise, print two lines.  The first of these lines should contain the string `"Yes"`.  The second line should contain $N$ spaceseparated integers $A_1, A_2, \ldots, A_N$. ### Constraints  $1 \le T \le 5 \cdot 10^5$  $1 \le N, K, M \le 5 \cdot 10^5$  $1 \le X_i \le K$ for each valid $i$  $1 \le Y_i, Z_i \le N$ for each valid $i$  all triplets are pairwise distinct  the sum of $N$ over all test cases does not exceed $5 \cdot 10^5$  the sum of $K$ over all test cases does not exceed $5 \cdot 10^5$  the sum of $M$ over all test cases does not exceed $5 \cdot 10^5$ ### Example Input ``` 3 3 3 2 1 1 2 2 2 3 3 1 1 1 1 1 3 1 1 1 1 2 ``` ### Example Output ``` Yes 2 1 2 Yes 1 1 1 No ```Author:  kmaaszraa 
Editorial  https://discuss.codechef.com/problems/HDDN 
Tags  cook111, easymedium, implementation, kmaaszraa, taran_1407 
Date Added:  18102019 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 