#K88337. Counting Flower Clusters
Counting Flower Clusters
Counting Flower Clusters
You are given a network of flower clusters represented as nodes in an undirected graph. Some clusters are known to have growing flowers. Due to a certain growth range, flowers might also grow in neighboring clusters within a maximum distance \( x \) (in terms of the number of trails or edges) from any of the known clusters.
The task is to determine the total number of clusters that could potentially have flowers growing. More precisely, starting from each known cluster, you can spread outwards via breadth-first search along the trails, and any cluster reached within at most \( x \) edges is considered as a candidate.
Note: The clusters are numbered from 1 to \( n \), and the provided trails indicate bidirectional connections between clusters.
inputFormat
The first line contains three integers \( n \), \( k \), and \( x \) where:
- \( n \) is the number of clusters.
- \( k \) is the number of clusters with known flower growth.
- \( x \) is the maximum distance (number of trails) through which flowers can spread.
The second line contains \( k \) distinct integers, each representing a cluster with known flowers.
The third line contains an integer \( m \), the number of trails connecting clusters.
Each of the following \( m \) lines contains two integers \( u \) and \( v \), indicating that there is an undirected trail connecting cluster \( u \) and cluster \( v \).
outputFormat
Output a single integer representing the total number of clusters where flowers might be growing (i.e. all clusters reachable within \( x \) trails from any known cluster).
## sample5 1 2
2
4
1 2
2 3
3 4
4 5
4