#abc243e. E - Edge Deletion

E - Edge Deletion

Score : 500500 points

问题描述

给定一个含有 NN 个顶点和 MM 条边的简单连通无向图。
ii 条边连接顶点 AiA_i 和顶点 BiB_i,其长度为 CiC_i

在满足以下条件的情况下,删除一定数量的边。找出能够删除的最大边数。

  • 删除后,图仍然保持连通状态。
  • 对于每一对顶点 (s,t)(s, t),在删除前后,顶点 ss 和顶点 tt 之间的距离保持不变。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a simple connected undirected graph with NN vertices and MM edges.
Edge ii connects Vertex AiA_i and Vertex BiB_i, and has a length of CiC_i.

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 (s,t)(s, t), the distance between ss and tt 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 ss and tt, tt is reachable from ss by traversing edges.
The distance between Vertex ss and Vertex tt is the length of a shortest path between ss and tt.

Constraints

  • 2N3002 \leq N \leq 300
  • N1MN(N1)2N-1 \leq M \leq \frac{N(N-1)}{2}
  • 1Ai<BiN1 \leq A_i \lt B_i \leq N
  • 1Ci1091 \leq C_i \leq 10^9
  • (Ai,Bi)(Aj,Bj)(A_i, B_i) \neq (A_j, B_j) if iji \neq j.
  • The given graph is connected.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 B1B_1 C1C_1

A2A_2 B2B_2 C2C_2

\vdots

AMA_M BMB_M CMC_M

Output

Print the answer.

Sample Input 1

3 3
1 2 2
2 3 3
1 3 6

Sample Output 1

1

The distance between each pair of vertices before the deletion is as follows.

  • The distance between Vertex 11 and Vertex 22 is 22.
  • The distance between Vertex 11 and Vertex 33 is 55.
  • The distance between Vertex 22 and Vertex 33 is 33.

Deleting Edge 33 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 11.

Sample Input 2

5 4
1 3 3
2 3 9
3 5 3
4 5 3

Sample Output 2

0

No edge can be deleted.

Sample Input 3

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

Sample Output 3

5

update @ 2024/3/10 10:27:34