luogu#P4962. 朋也与光玉
朋也与光玉
Background
Even if each light is small, if many gather together, it will surely become a very mysterious and great power.
Nagisa’s death, Ushio’s departure... Tomoya’s life has almost fallen into complete darkness.
But is this the end?

Problem Description
Hikarizaka Town is a directed graph with nodes (numbered to ) and directed edges. Each node has a light orb. There are types of light orbs, numbered to .
To change everything, Tomoya needs to collect all types of light orbs. He may start from any node and walk freely in the graph, but he will not pass through the same node twice. Each time he encounters a light orb, he will collect it. After collecting light orbs, that is, after visiting nodes, he will stop collecting. Design a plan so that Tomoya can collect all types of light orbs, and the total path length is as short as possible.
In other words, each node has one color. Find a shortest path that visits exactly nodes and covers all colors exactly once. You need to output the length of this path.
Input Format
The first line contains three positive integers , representing the number of nodes, the number of edges, and the number of light orb types.
The second line contains positive integers to , where is the type index of the light orb on node .
The next lines each contain three positive integers , indicating a directed edge from to with length .
Output Format
Output one line. If a solution exists, output a positive integer representing the length of the shortest path that satisfies the condition. If no solution exists, output Ushio! (without quotes).
8 19 3
1 2 0 1 1 1 2 0
3 1 4
3 2 2
1 4 1
7 4 10
5 4 7
4 2 5
5 6 4
4 7 3
8 5 10
3 6 8
8 1 10
5 2 10
6 7 3
4 3 9
6 2 5
4 8 10
3 8 3
1 7 8
1 3 9
11
5 6 3
0 1 1 2 2
1 2 3
2 3 2
1 4 2
5 2 1
1 3 4
5 4 1
Ushio!
6 13 3
2 2 2 1 0 2
1 4 4
3 4 8
5 3 2
4 5 6
2 3 2
1 3 3
1 2 4
3 1 4
6 3 6
3 2 6
2 1 6
4 2 9
5 2 1
7
Hint
Constraints: ,,,.
It is guaranteed that the graph has no multiple edges or self-loops.
Translated by ChatGPT 5