Темы:
Algorithms on graphs
Shortest paths in a graph
Given an undirected connected weighted graph with N vertices and M edges that contains neither loops nor double edges. I -e (1<=i<=M) edge connects vertex ai and the vertex bi at distance ci . We will assume that the loop is an edge, where ai=bi (1<=i<=M), and double edges are two edges where (ai,bi)=(aj,bj) or (ai,bi)=(bj,aj) (1<=i<j<;=M). A connected graph is a graph in which there is a path between every pair of distinct vertices. Find the number of edges that do not belong to any shortest path between any pair of distinct vertices.< br />
Input
The first line specifies two integers N and M (2<=N<=100 , N−1<=M<=min(N⋅(N−1)/2,1000)). This is followed by M lines of three integers per line: ai , bi , ci (1<=ai,bi<=N< /span>, 1<=ci<=1000). This graph does not contain loops or double edges. This graph is connected .
Imprint
Print the number of edges in the graph that do not belong to any shortest path between any pair of distinct vertices.
Examples
# |
Input |
Output |
Explanations |
1 |
3 3
1 2 1
1 3 1
2 3 3
|
1
|
In this graph, the shortest paths between all pairs of distinct vertices are:
Shortest path from node 1 to node 2: node 1 → vertex 2, path length is 1.
Shortest path from node 1 to node 3: node 1 → vertex 3, path length is 1.
Shortest path from node 2 to node 1: node 2 → vertex 1, path length is 1.
Shortest path from node 2 to node 3: node 2 → peak 1 → vertex 3, path length is 2.
Shortest path from node 3 to node 1: node 3 → vertex 1, path length is 1.
Shortest path from node 3 to node 2: node 3 → peak 1 → vertex 2, path length is 2.
So the only edge that is not contained in any shortest path is the edge of length 3 connecting vertex 2 and vertex 3, so the output should be 1. |
2 |
3 2
1 2 1
2 3 1
|
0
|
Each edge is contained in some shortest path between a pair of distinct vertices. |
|