#P16437. [XJTUPC 2026] 全都登不上 2

[XJTUPC 2026] 全都登不上 2

Background

:::epigraph[------ Shirost] Chapter 1: Settling down.

Chapter 2: That heavy rain ruined my OI dream.

Chapter 3: First prize in the school programming contest is also a first prize.

Chapter 4: What does it mean that Domjudge cannot be opened?

Chapter 5: A mysterious network outage ruined my dream of getting first prize.

Chapter 6: Settling down, preparing for the 2027 school programming contest. :::

Problem Description

There are nn computer rooms, belonging to mm groups. The ii-th computer room belongs to group aia_i. The OJ server is placed in some computer room in group vv.

A mysterious administrator made a mistake and “isolated” kk groups. After a group is isolated, the computer rooms in that group will be unable to contact any computer rooms in any other group. Any groups that are not isolated can communicate normally with each other. Group vv will never be isolated.

Please calculate: after isolating these kk groups, how many computer rooms in total can still access the OJ server.

Input Format

The first line contains three integers nn, mm, and kk (1≤k<m≤n≤1051 \le k < m \le n \le 10^5), separated by a single space, representing the total number of computer rooms, the total number of groups, and the number of isolated groups.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤m1 \le a_i \le m), separated by a single space, where aia_i denotes the group ID of the ii-th computer room.

The third line contains an integer vv (1≤v≤m1 \le v \le m), representing the group ID where the OJ server is located.

The next kk lines each contain an integer uu (1≤u≤m1 \le u \le m, u≠vu \ne v), representing the ID of an isolated group. It is guaranteed that each group is isolated at most once.

Output Format

Output one line containing an integer, representing the number of computer rooms that can access the OJ in the end.

6 4 2
1 2 4 3 2 1
1
2
3
3

Hint

Translated by ChatGPT 5