Under construction

Still being built. Things may change

Paint the Roads

Time limit1.5sMemory limit1024 MB

Summary
Given a graph with colored roads, decide whether a walk can leave each building with its target color, and output such a walk within 1,000,000 visits if one exists.
Level

Hard8 of 10

Topics
Graph, Implementation
Solved
No attempts yet

Problem

A city has NN buildings and MM roads. Road ii connects building uiu_i and building viv_i in both directions. No two roads connect the same pair of buildings. Each road is painted with one of KK colors, and road ii has color cic_i. The paint is still wet, so the building visited right after traveling along road ii is painted over with color cic_i. Initially, every building has color 00. (1≤i≤M1 \le i \le M)

Performance artist Eunha wants to paint the buildings using the following method.

  • Eunha picks a starting building and goes there.
  • Repeat the following step until every building has its desired color.
    • From her current building aa, she moves along a road with color pp to an adjacent building bb. She may visit the same building many times. There must exist an ii with (a,b,p)=(ui,vi,ci)(a,b,p) = (u_i,v_i,c_i) or (vi,ui,ci)(v_i,u_i,c_i).
    • She paints building bb with color pp, regardless of its previous color.

Eunha wants building jj to have color rjr_j for every jj with 1≤j≤N1 \le j \le N. Determine whether this is possible. If it is, output one way to do it.

Input

The first line contains the number of buildings NN, the number of roads MM, and the number of colors KK, separated by spaces. (2≤N≤100 0002 \le N \le 100\,000, 1≤M≤200 0001 \le M \le 200\,000, 1≤K≤100 0001 \le K \le 100\,000)

The second line contains the target colors r1,r2,⋯ ,rNr_1, r_2, \cdots, r_N, separated by spaces. (1≤rj≤K1 \le r_j \le K)

Each of the next MM lines contains uiu_i, viv_i, and cic_i, separated by spaces. (1≤ui<vi≤N1 \le u_i < v_i \le N, 1≤ci≤K1 \le c_i \le K, and if i≠ji \ne j then (ui,vi)≠(uj,vj)(u_i, v_i) \ne (u_j, v_j))

All input values are integers.

Output

For every jj with 1≤j≤N1 \le j \le N, if building jj can be painted with color rjr_j, print YES on the first line. Otherwise print NO.

If you print YES, print the number of buildings Eunha visits on the second line, and the building numbers she visits in order on the third line, separated by spaces. The total number of visits must not exceed 1 000 0001\,000\,000. After visiting the buildings in this order, every building jj must have color rjr_j. It can be proven that whenever painting is possible, it can be done with at most 1 000 0001\,000\,000 visits for every valid input.

Examples2

  1. Example 1

    Input
    4 6 3
    1 2 3 3
    1 2 1
    1 3 2
    1 4 3
    2 3 1
    2 4 2
    3 4 3
    
    Expected output
    YES
    5
    4 3 4 2 1
    
  2. Example 2

    Input
    4 2 3
    1 1 3 3
    1 2 1
    3 4 3
    
    Expected output
    NO