#P17122. [ICPC 2025 Shanghai R] Hamu

    ID: 19459 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>并查集2025上海Special Judge生成树二分图最近公共祖先 LCA构造ICPCAd-hoc分类讨论

[ICPC 2025 Shanghai R] Hamu

Problem Description

Dingdong plans to travel to the country of Hamu.

The country of Hamu consists of nn cities and mm bidirectional roads. Before this trip, Dingdong has already visited city ii exactly aia_i times. During this trip, Dingdong plans to enter Hamu at city ss. On each subsequent day, Dingdong will travel along a certain road to a city and visit that city once. At the end of the final day’s visit, Dingdong should be at city ss and leave Hamu from city ss. Note that on the day of entering the country of Hamu, Dingdong does not visit city ss.

Dingdong hopes that after this trip, combined with his previous visits, every city in Hamu will have been visited by him an even number of times. Dingdong has limited time and can visit at most 5n5n cities during this trip. Please help him construct a valid trip plan, or tell him if it is impossible.

Input Format

The input contains multiple testcases. The first line of the input contains an integer TT (1T2×1051 \le T \le 2 \times 10^5), the number of testcases.

For each testcase, the first line contains three integers n,m,sn, m, s ($1 \le n \le 2 \times 10^5, 0 \le m \le 2 \times 10^5, 1 \le s \le n$), where nn is the number of cities, mm is the number of roads, ss is the index of the starting city.

The next line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n (0ai1090 \le a_i \le 10^9), the number of times Dingdong has visited for each city.

The next mm lines each contain two integers ui,viu_i, v_i (1ui,vin1 \le u_i, v_i \le n), indicating an undirected road connecting city uiu_i and city viv_i. There can be multiple edges and self loops. In other words, it’s not guaranteed that uiviu_i \ne v_i, and it’s not guaranteed that (ui,vi)(uj,vj)(u_i, v_i) \ne (u_j, v_j) for iji \ne j.

It’s guaranteed that the sum of nn and the sum of mm over all testcases does not exceed 2×1052 \times 10^5, respectively.

Output Format

For each testcase, if there’s no valid trip plan, print No in a single line.

Otherwise, print Yes in a single line first, then print an integer kk (0k5n0 \le k \le 5n) in the next line, representing the total number of visits during this trip. In the following line, print the indexes of the cities visited in order.

5
4 4 1
1 1 1 1
1 2
2 3
3 4
4 1
5 7 1
9 4 3 11 7
1 2
2 5
2 4
3 4
2 3
1 3
4 5
2 2 2
114 514
1 2
1 2
5 0 1
114 514 19 19 810
2 1 1
3 5
1 2
Yes
4
2 3 4 1
Yes
6
2 4 5 2 3 1
Yes
0

No
Yes
2
2 1

Hint

For the first testcase, after visiting along the route 123411 \to 2 \to 3 \to 4 \to 1, cities 1,2,3,41, 2, 3, 4 have been visited 2,2,2,22, 2, 2, 2 times respectively, meeting the requirement.