P16437 [XJTUPC 2026] Nobody Can Log In 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. :::

Description

There are $n$ computer rooms, belonging to $m$ groups. The $i$-th computer room belongs to group $a_i$. The OJ server is placed in some computer room in group $v$. A mysterious administrator made a mistake and “isolated” $k$ 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 $v$ will never be isolated. Please calculate: after isolating these $k$ groups, how many computer rooms in total can still access the OJ server.

Input Format

The first line contains three integers $n$, $m$, and $k$ ($1 \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 $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le m$), separated by a single space, where $a_i$ denotes the group ID of the $i$-th computer room. The third line contains an integer $v$ ($1 \le v \le m$), representing the group ID where the OJ server is located. The next $k$ lines each contain an integer $u$ ($1 \le u \le m$, $u \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.

Explanation/Hint

Translated by ChatGPT 5