#C6895. Illogical Population Claims
Illogical Population Claims
Illogical Population Claims
You are given a kingdom with M regions and R bidirectional roads connecting some of these regions. Each region has a specified population. For each test case, you need to identify the connected components of the kingdom. A connected component is considered illogical if there exists at least one pair of regions within that component such that the absolute difference of their populations exceeds a given threshold P (i.e. \(|pop_i - pop_j| > P\)). Your task is to count the number of such illogical connected components in each test case.
Note: The road network can form cycles and may be disconnected.
inputFormat
The input is read from standard input (stdin) and is formatted as follows:
T M R P pop1 pop2 ... popM A1 B1 A2 B2 ... (R lines representing roads)</p>... (repeat the above block for each of the T test cases)
Where:
- T: number of test cases
- M: number of regions
- R: number of roads
- P: the population difference threshold
- pop1, pop2, ..., popM: populations of the regions (1-indexed)
- Each of the next R lines contains two integers A and B, representing a bidirectional road between region A and region B.
outputFormat
For each test case, output a single integer on a new line representing the number of illogical connected components in that test case. The output is written to standard output (stdout).
## sample1
4 4 10
30 15 25 40
1 2
2 3
3 4
4 1
1
</p>