#K6606. Exploring Unique Cities with Train Routes
Exploring Unique Cities with Train Routes
Exploring Unique Cities with Train Routes
You are given a set of cities and a list of direct train connections between them. Each train route is defined by two city indices and a distance. Starting from any city, a passenger can travel along the train routes following a simple rule: the distance of each subsequent train taken must not exceed the distance of the previous train. Initially, the passenger can choose any train route because the allowed distance is considered to be \(\infty\). Your task is to determine the maximum number of unique cities that can be visited under these constraints.
Input Format: The first line contains two integers \(N\) (the number of cities) and \(M\) (the number of train routes). The second line contains \(N\) integers representing the coordinates of the cities (although the coordinates do not affect the route constraints). The following \(M\) lines each contain three integers \(u\), \(v\), and \(d\) representing a direct train connection between city \(u\) and city \(v\) with a distance of \(d\).
Output Format: Output a single integer, the maximum number of unique cities a passenger can visit while following the rule that each chosen train's distance is at most the distance of the previous train.
Note: The connections are bidirectional.
inputFormat
The input is read from standard input (stdin) in the following order:
- The first line contains two space-separated integers \(N\) and \(M\), where \(N\) is the number of cities and \(M\) is the number of train routes.
- The second line contains \(N\) space-separated integers representing the coordinates of the cities.
- The next \(M\) lines each contain three space-separated integers \(u\), \(v\), and \(d\), describing a train route between city \(u\) and city \(v\) with distance \(d\).
outputFormat
Print a single integer to standard output (stdout) — the maximum number of unique cities that can be visited following the train route constraints.
## sample4 4
1 3 6 10
1 2 2
2 3 3
3 4 4
2 4 7
4