#P1078. [NOIP 2012 普及组] 文化之旅(疑似错题)
[NOIP 2012 普及组] 文化之旅(疑似错题)
Description
A messenger plans to travel among countries. Each time he enters a country, he learns that country's culture. He refuses to learn any culture more than once; that is, once he has learned a culture, he cannot visit any other country that has the same culture. Different countries may share the same culture. Different cultures view other cultures differently: some cultures reject certain foreign cultures. Specifically, if he has learned a culture, then he cannot enter any country whose local culture rejects that learned culture. He also learns the local culture at both the start and the end.
Given the geography (countries and roads), each country's culture, each culture's view of other cultures, the start and end countries, and road distances, find the minimum total distance from the start to the end.
Input Format
The first line contains five integers separated by single spaces, denoting the number of countries (indexed to ), the number of cultures (indexed to ), the number of roads, and the indices of the start and the end, respectively. It is guaranteed that .
The second line contains integers. The -th integer denotes the culture of country .
The next lines each contain integers separated by single spaces. Let the -th integer on the -th line be . If , then culture rejects visitors who have learned culture (when , it means rejecting visitors of the same culture). If , it does not reject. Note that rejecting does not imply rejects .
The next lines each contain three integers separated by single spaces, indicating an undirected road between countries and with distance . It is guaranteed that , and there may be multiple roads between the same pair of countries.
Output Format
Output a single integer: the minimum total distance for the messenger to travel from to . If it is impossible, output .
2 2 1 1 2
1 2
0 1
1 0
1 2 10
-1
2 2 1 1 2
1 2
0 1
0 0
1 2 10
10
Hint
Explanation for Sample 1: Since reaching country must pass through country , and the culture of country rejects the culture of country , it is impossible to reach country .
Explanation for Sample 2: The route is .
Constraints:
- For of the testdata:
- .
- .
- .
- .
- .
- .
- .
- .
This is NOIP 2012 Junior Problem 4.
Translated by ChatGPT 5
京公网安备 11011102002149号