atcoder#ABC243E. [ABC243E] Edge Deletion
[ABC243E] Edge Deletion
Score : points
Problem Statement
You are given a simple connected undirected graph with vertices and edges. Edge connects Vertex and Vertex , and has a length of .
Let us delete some number of edges while satisfying the conditions below. Find the maximum number of edges that can be deleted.
- The graph is still connected after the deletion.
- For every pair of vertices , the distance between and remains the same before and after the deletion.
Notes
A simple connected undirected graph is a graph that is simple and connected and has undirected edges. A graph is simple when it has no self-loops and no multi-edges. A graph is connected when, for every pair of two vertices and , is reachable from by traversing edges. The distance between Vertex and Vertex is the length of a shortest path between and .
Constraints
- if .
- The given graph is connected.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3 3
1 2 2
2 3 3
1 3 6
1
The distance between each pair of vertices before the deletion is as follows.
- The distance between Vertex and Vertex is .
- The distance between Vertex and Vertex is .
- The distance between Vertex and Vertex is .
Deleting Edge does not affect the distance between any pair of vertices. It is impossible to delete two or more edges while satisfying the condition, so the answer is .
5 4
1 3 3
2 3 9
3 5 3
4 5 3
0
No edge can be deleted.
5 10
1 2 71
1 3 9
1 4 82
1 5 64
2 3 22
2 4 99
2 5 1
3 4 24
3 5 18
4 5 10
5