P17649 [IO 2025 #1] Skeletons, Bones, Graveyards, Skulls

Description

Pharloom is a kingdom crisscrossed by silk paths. Each path is a taut straight silk thread connecting two villages. The cunning villain "Skull Tyrant" plans to strike this web of paths vertically. View the kingdom as a graph: the vertices are the villages, where village $i$ has coordinates $(x_i,y_i)$ on the plane; the edges are the silk paths connecting villages. The segments representing roads may intersect outside villages, but you cannot switch from one road to another at such intersection points. The inhabitants have guessed $q$ positions where the tyrant might attack. If the tyrant attacks along the vertical line with $x$-coordinate $X$, the following are removed: - all villages with $x_i=X$; - all roads connecting villages $i,j$ with $\min(x_i,x_j)\le X\le\max(x_i,x_j)$. Help the inhabitants: for each possible attack position, find the number of connected components remaining in the kingdom after the attack. All queries are independent: when answering the current query, do not consider previous attacks. A connected component of a graph is a set of vertices such that any vertex in the set can reach any other vertex in the set along edges, but cannot reach any vertex outside the set along edges.

Input Format

Each test contains multiple test cases. The first line contains an integer $t$, the number of test cases, with $1\le t\le5000$. Then each test case is described. The first line of each test case contains three integers $n,m,q$, the number of villages, roads, and possible attack positions, with $1\le n\le10^5$, $0\le m\le\min(10^5,\frac{n(n-1)}2)$, $1\le q\le10^5$. The second line contains $n$ integers $x_i$, the $x$-coordinates of the villages. The third line contains $n$ integers $y_i$, the $y$-coordinates of the villages. The coordinates satisfy $-10^9\le x_i,y_i\le10^9$. Each of the next $m$ lines contains two integers $u_i,v_i$, the indices of the two villages connected by a road, with $1\le u_i,v_i\le n$ and $u_i\ne v_i$. The last line contains $q$ integers, the $x$-coordinates of the possible attack positions, each with absolute value at most $10^9$. It is guaranteed that no two villages in the same test case have the same coordinates. It is guaranteed that the sums of $n$, $m$, and $q$ over all test cases each do not exceed $10^5$.

Output Format

For each test case, output one line with $q$ integers, the answers to the queries. Note that the queries are independent.

Explanation/Hint

The graph in the sample is shown below: :::align{center} ![](https://cdn.luogu.com.cn/upload/image_hosting/rmff2kl5.webp) ::: Translated by QwenWork