DMOPC '20 Contest 1 P5 - Victor Takes Over Canada

View as PDF

Submit solution


Points: 17 (partial)
Time limit: 2.2s
Memory limit: 512M

Author:
Problem types

NOW I HAVE THE POWER ~ Victor, 2019

Victor, using the money he earned from selling horseshoe crabs, has managed to buy alien technology!

Using this alien technology, he terraforms Canada into a network of N cities, numbered 1,2,,N connected by exactly N1 highways. Victor lives in city 1. He also hires K aliens (numbered 1,2,,K) to guard the cities with. As alien guards are expensive, each city has exactly 1 guard assigned to it. An alien can be assigned to multiple cities, but can be present in at most one city at a time (thankfully, these aliens don't teleport).

Over the following M minutes, one of the following happens:

  • 1 c k: Alien k is assigned to guard city c, replacing its previous alien guard.
  • 2 u: The resistance plans a siege of city u and wishes to know the maximum possible number of guards that can come reinforce city u.

As the head of intelligence at the resistance, you are tasked with writing a program to calculate these scenarios. A guard is able to reinforce city u if and only if u lies on the unique path between any one of its assigned cities and city 1.

If only Victor hadn't been given the roll of paper of power…

Constraints

For all subtasks:

1KN

Subtask 1 [10%]

1N,M2000

Subtask 2 [20%]

1N,M200000

The alien guards are never reassigned.

Subtask 3 [40%]

1N,M200000

Subtask 4 [30%]

1N500000

1M300000

Input Specification

The first line will contain three space-separated integers, N, K, and M.
The second line will contain N space-separated integers, c1,c2,,cN, indicating the cith alien is assigned to city i.
The next N1 lines will each contain a pair of integers, ai,bi, indicating there is an edge between ai and bi.
The next M lines will each contain a query.

Output Specification

For each expedition, output the maximum possible number of guards that can come reinforce city u.

Sample Input 1

Copy
5 5 5
3 4 1 1 2
1 2
1 3
2 4
2 5
2 2
2 1
1 2 1
2 2
2 1

Sample Output 1

Copy
3
4
2
3

Sample Input 2

Copy
7 5 4
1 2 3 4 3 2 1
1 2
1 3
1 4
4 5
4 6
4 7
2 4
2 1
2 2
2 7

Sample Output 2

Copy
4
4
1
1

Comments

There are no comments at the moment.