#P4312. [COI 2009] OTOCI
[COI 2009] OTOCI
Description
Not long ago, Mirko founded a travel agency called “Polar Dream.” The agency bought islands near the Arctic and offers sightseeing services.
The most popular attraction is, of course, the emperor penguins. These little fellows often move in groups between the islands. Mirko’s agency suffered a major setback, making cruise tours no longer cost-effective. The agency will build bridges between islands and use sightseeing buses to carry tourists.
Mirko wants to develop a computer program to manage the bridge-building process to avoid unexpected errors. The islands are labeled from to . Initially, there are no bridges between islands, and the number of emperor penguins on each island is known. Although the number on each island may change, it is always within . Your program must process the following three commands:
bridge u v: Ask whether nodes and are connected. If they are, outputno; otherwise outputyes, and add an undirected edge between and .penguins u x: Set the weight of node to .excursion u v: If nodes and are not connected, outputimpossible. Otherwise, output the sum of the weights of the nodes on the path from to .
There are operations in total.
Input Format
- The first line contains an integer , the number of nodes.
- The second line contains integers; the -th integer is the initial weight of node .
- The third line contains an integer , the number of operations.
- Each of the next lines contains one operation as described above.
Output Format
Output the results of all bridge and excursion operations, one answer per line.
5
4 2 4 5 6
10
excursion 1 1
excursion 1 2
bridge 1 2
excursion 1 2
bridge 3 4
bridge 3 5
excursion 4 5
bridge 1 3
excursion 2 4
excursion 2 5
4
impossible
yes
6
yes
yes
15
yes
15
16
6
1 2 3 4 5 6
10
bridge 1 2
bridge 2 3
bridge 4 5
excursion 1 3
excursion 1 5
bridge 3 4
excursion 1 5
penguins 3 10
excursion 1 3
bridge 1 5
yes
yes
yes
6
impossible
yes
15
13
no
Hint
Constraints
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号