Coder me run
View as PDFFor a programmer, besides knowledge and professional skills, regular exercise to keep the body healthy is very important. Understanding that, VNOI has organized the "Coder me run" competition to encourage the sports training movement of programmers nationwide.
The competition will be held at ~n~ locations. These locations are connected to each other by ~m~ two-way roads, the ~i~-th road connects two locations ~u_i~ and ~v_i~. Between any two locations, it is always possible to reach each other through one or more roads. At the same time, between any two locations, there is no more than one edge connecting them.
This year, the theme of the Coder me run race is "Color". The organizers have colored the ~i~-th road with color ~c_i~. When passing through any road, the color of the contestant will be colored with the color of that road. When arriving at any location, the color of that location will be colored with the current color of the contestant. Initially, the contestant is not colored and can choose any location to start. To complete their test, the contestant needs to color the location ~u~ with color ~s_u~.
As a member of the organizing committee, you are assigned the task of checking whether the contestant has any way to complete their test or not. Specifically, you need to provide any running path to color the locations that meet the requirements of the organizers, or indicate that it is infeasible.
Input
The first line consists of three integers ~n~, ~m~ (~1 \le n \le 20\,000~, ~n-1 \le m \le \min \big(\frac{n(n-1)}{2},20\,000 \big)~) — the number of locations in the competition and the number of roads.
The second line consists of ~n~ integers ~s_1, s_2, \ldots, s_n~ (~1 \le s_i \le n~) — the colors that the contestant needs to color for the locations.
The next ~m~ lines, the ~i~-th line consists of three integers ~u_i~, ~v_i~, ~c_i~ (~1 \le u_i, v_i, c_v \le n~, ~u_i \ne v_i~) — describing two locations connected by the ~i~-th road and the color of that road.
The input data ensures that between any two locations, it is possible to reach each other through one or more roads. At the same time, between any two locations, there is no more than one edge connecting them.
Output
On the first line, print "YES" (without quotes) if there exists a running path to color the locations that meet the requirements of the organizers; otherwise, print "NO" (without quotes).
If the first line prints "YES", you need to print the number ~k~ no more than ~10^5~ on the second line, which is the number of locations in the running path found. It can be proven that under the limit of this problem, if there exists a running path that satisfies the condition, there also exists a running path that does not pass more than ~10^5~ locations.
Next, you need to print ~k~ integers ~p_1, p_2, \ldots, p_k~ (~1 \le p_i \le n~ for all ~1 \le i \le k~) on the third line to indicate the order of the locations passed in the running path.
Note that you do not need to find the running path that minimize the number of locations.
Scoring
| Subtask | Score | Constraints |
|---|---|---|
| ~1~ | 1250 | ~n \le 16~ |
| ~2~ | 1500 | ~n \le 200~ |
| ~3~ | 750 | no additional constraints |
| Total | 3500 |
Sample Input 1
3 2
1 1 2
1 2 1
2 3 2
Sample Output 1
YES
4
2 1 2 3
Sample Input 2
4 4
1 1 2 3
1 2 1
2 3 2
1 4 1
3 4 1
Sample Output 2
NO
Sample Input 3
5 7
1 2 2 1 3
1 2 1
1 3 3
2 4 2
5 1 1
5 2 3
5 3 2
5 4 1
Sample Output 3
YES
7
2 1 5 4 2 5 3
Notes
In the first example, we have an illustration of the running path that satisfies the requirements of the problem below. The two colors ~1~ and ~2~ are represented by red and green.

Illustration of the first example.
In the second example, since the roads are colored with only colors ~1~ and ~2~, it is impossible to color location ~4~ with color ~3~.
In the third example, similarly, we have an illustration of the running path below. The color ~3~ is represented by blue.

Illustration of the second example.
Comments