#P16395. [ECUSTPC 2026 Spring] 星之所在
[ECUSTPC 2026 Spring] 星之所在
Background
:::epigraph Star farming is a great invention of ancient China. :::
Problem Description
Pheonix has arrived in outer space. There are galaxies, numbered . These galaxies are connected by bidirectional wormholes, and every galaxy can be reached from any other through these wormholes.
Each galaxy contains some stars. The number of stars in galaxy is .
Pheonix will make trips through wormholes between galaxies. During one trip, Pheonix will not visit the same galaxy more than once.
Pheonix knows little about astronomy, but he has sharp mathematical insight. For each trip, he wants to ask Little T the following question:
- Put the star counts of the galaxies passed on the wormhole trip from galaxy to galaxy (including the start and end) into a multiset , that is, $S = \{s_i : i \text{ is on the path from } x \text{ to } y\}$.
- Do there exist elements in whose frequency is strictly greater than ? Here is an integer specified by Pheonix in each query. If yes, output all such elements.
Please help Little T answer these queries.
Input Format
The first line contains an integer , the number of testdata.
For each testdata, the first line contains two integers and , representing the number of galaxies and the number of Pheonix's trips.
The next line contains integers , where is the number of stars in galaxy .
The next lines each contain two integers and , indicating a wormhole connecting and .
The next lines each contain three integers $x, y, k \ (1 \le x, y \le n, 2 \le k \le n, x \ne y)$, representing the start and end of a trip, and the query parameter.
It is guaranteed that over all testdata. It is also guaranteed that in each testdata, the wormholes make all galaxies mutually reachable.
Output Format
For each testdata, output lines. The -th line is the answer to the -th query:
- If there exist elements in whose frequency is strictly greater than , output those star counts in increasing order of the star count (not by frequency).
- Otherwise, output a single integer .
2
6 4
1 2 2 1 2 3
1 2
2 3
2 4
4 5
5 6
3 6 2
1 4 3
1 6 2
1 5 3
7 5
1 2 1 3 2 2 4
1 2
1 3
2 4
2 5
3 6
6 7
4 5 2
4 7 3
5 6 4
3 1 2
7 5 2
2
1
-1
1 2
2
-1
1 2
1
-1
Hint
Explanation for Sample 1
:::align{center}
:::
The figure above shows the wormhole connections and star counts for the first testdata.
In the first query, the trip is from galaxy to galaxy with parameter . The galaxies on the path are , with star counts . The star count that appears strictly more than the threshold times is .
Translated by ChatGPT 5