luogu#P5163. WD与地图

WD与地图

Background

WD spends all day immersed in maps and cannot pull himself out.

Problem Description

The map that CX asks WD to study can be seen as a directed graph with nn nodes and mm edges. Since the government is trying to improve people's lives, they will remove some useless roads and use the saved money for economic development.

Each city has its own development level sis_i. For easier management, the government divides the whole map into some regions. Two nodes u,vu, v are in the same region if and only if u,vu, v can reach each other. The government wants to know, at certain times, the sum of the development levels of the top kk most developed cities in a region, in order to judge the construction situation.

That is, there are three operations in total:

1 a b means the government removes the edge from aa to bb, and it is guaranteed that this edge exists.

2 a b means the government invests money to build city aa, increasing its development level by bb.

3 a b means the government wants to know the sum of the development levels of the top bb cities (by development level) in the region where city aa is located. If there are fewer than bb cities in the region, output the sum of the development levels of all cities in that region.

Input Format

The first line contains three integers n,m,qn, m, q, meaning there are nn nodes, mm edges, and qq queries.

The second line contains nn positive integers, representing sis_i, i.e., the development level of each city.

The next mm lines each contain two integers u,vu, v, indicating that initially there is an edge from uu to vv.

The next qq lines describe the qq queries, in the format given in the description.

Output Format

For each query operation, output one integer, representing the sum of development levels.

5 8 8
4 2 1 1 3
2 5
4 2
5 3
1 3
4 5
5 1
1 5
1 4
3 3 1
1 4 5
3 3 3
3 4 1
3 1 5
3 2 4
1 5 3
2 3 4
1
1
4
10
10

Hint

$subtask1(19pts):~n\le 100,000,~m\le 200,000,~q\le 200,000$, number of delete operations ×m1,000,000\times m\le 1,000,000.

$subtask2(39pts):~n\le 5,000,~m\le 8,000,~q\le 200,000$.

$subtask3(42pts):~n\le 100,000,~m\le 200,000,~q\le 200,000$.

It is guaranteed that at any time the development level 109\le 10^9. There are no multiple edges (reverse edges are not considered multiple edges) and no self-loops.

Translated by ChatGPT 5