#atcoderABC051D. Candidates of No Shortest Paths
Candidates of No Shortest Paths
Problem
You are given an undirected connected weighted graph with vertices and edges that contains neither self-loops nor double edges.
The -th edge connects vertex and vertex with a distance of .
Here, a self-loop is an edge where , and double edges are two edges where or .
A connected graph is a graph where there is a path between every pair of different vertices.
Find the number of the edges that are not contained in any shortest path between any pair of different vertices.
Constraints
- is an integer.
- The given graph contains neither self-loops nor double edges.
- The given graph is connected.
Input
The input is given from Standard Input in the following format:
Output
Print the number of the edges in the graph that are not contained in any shortest path between any pair of different vertices.
Example : 1. in
3 3
1 2 1
1 3 1
2 3 3
Example : 1. out
1
In the given graph, the shortest paths between all pairs of different vertices are as follows:
- The shortest path from vertex to vertex is: vertex → vertex , with the length of .
- The shortest path from vertex to vertex is: vertex → vertex , with the length of .
- The shortest path from vertex to vertex is: vertex → vertex , with the length of .
- The shortest path from vertex to vertex is: vertex → vertex → vertex , with the length of .
- The shortest path from vertex to vertex is: vertex → vertex , with the length of .
- The shortest path from vertex to vertex is: vertex → vertex → vertex , with the length of .
Thus, the only edge that is not contained in any shortest path, is the edge of length connecting vertex and vertex , hence the output should be .
Example : 2. in
3 2
1 2 1
2 3 1
Example : 2. out
0
Every edge is contained in some shortest path between some pair of different vertices.
相关
在下列比赛中: