#K36487. Unique Shortest Paths

    ID: 25765 Type: Default 1000ms 256MiB

Unique Shortest Paths

Unique Shortest Paths

We are given a weighted undirected graph representing a road network. The warehouse is located at node 1 and the remaining nodes represent different locations. Your task is to determine if the shortest path distances from the warehouse to all other locations are unique. Formally, let (d_i) denote the shortest distance from node 1 to node (i) (for (2 \le i \le n)). All these distances must be distinct. If they are, output "YES"; otherwise, output "NO".

inputFormat

The input is read from standard input. The first line contains two integers (n) and (m), representing the number of locations and the number of roads, respectively. Each of the following (m) lines contains three integers (a), (b), and (t) indicating that there is a bidirectional road between locations (a) and (b) with a travel time of (t).

outputFormat

Output a single line to standard output containing either "YES" if the shortest distances from node 1 to every other node are unique, or "NO" otherwise.## sample

5 6
1 2 4
1 3 2
2 3 1
2 4 5
3 4 3
3 5 4
YES