102434: [AtCoder]ABC243 E - Edge Deletion

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $500$ points

Problem Statement

You are given a simple connected undirected graph with $N$ vertices and $M$ edges.
Edge $i$ connects Vertex $A_i$ and Vertex $B_i$, and has a length of $C_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)$, the distance between $s$ and $t$ 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 $s$ and $t$, $t$ is reachable from $s$ by traversing edges.
The distance between Vertex $s$ and Vertex $t$ is the length of a shortest path between $s$ and $t$.

Constraints

  • $2 \leq N \leq 300$
  • $N-1 \leq M \leq \frac{N(N-1)}{2}$
  • $1 \leq A_i \lt B_i \leq N$
  • $1 \leq C_i \leq 10^9$
  • $(A_i, B_i) \neq (A_j, B_j)$ if $i \neq j$.
  • The given graph is connected.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $M$
$A_1$ $B_1$ $C_1$
$A_2$ $B_2$ $C_2$
$\vdots$
$A_M$ $B_M$ $C_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 $1$ and Vertex $2$ is $2$.
  • The distance between Vertex $1$ and Vertex $3$ is $5$.
  • The distance between Vertex $2$ and Vertex $3$ is $3$.

Deleting Edge $3$ 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 $1$.


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

Input

题意翻译

给你一张无重边无自环的联通带权无向图、 定义 $d(i,j)$ 是 $i$ 到 $j$ 的最短路径上的边权之和。 你需要删除一些边。要求删完之后的图满足下列条件: - 图仍然联通; - 对于 $1\le i,j\le N$,删边前的 $d(i,j)$ **等于**删边后的 $d(i,j)$。 现在问你最多能删多少条边。 数据保证: - $2\le N\le 300$ - $N-1\le M\le \frac{N(N-1)}{2}$ - $1\le u< v\le N$ - $1\le w\le 10^9$ - 图是联通的,没有重边和自环。 @[hellolin](/user/751017) 译。

Output

得分:500分 部分 问题描述 给定一个具有$N$个顶点和$M$条边的简单连接的无向图。 边$i$连接顶点$A_i$和顶点$B_i$,长度为$C_i$。 让我们在满足以下条件的情况下删除一些边。找出可以删除的最大边数。 - 删除后,图仍连接。 - 对于每一对顶点$(s, t)$,$s$和$t$之间的距离在删除前后保持不变。 注释 一个简单连接的无向图是一个简单、连接且具有无向边的图。 当图没有自环和多边时,图是简单的。 当对于每一对顶点$s$和$t$,可以通过遍历边从$s$到达$t$时,图是连接的。 顶点$s$和顶点$t$之间的距离是$s$和$t$之间最短路径的长度。 约束 - $2 \leq N \leq 300$ - $N-1 \leq M \leq \frac{N(N-1)}{2}$ - $1 \leq A_i \lt B_i \leq N$ - $1 \leq C_i \leq 10^9$ - 如果$i \neq j$,则$(A_i, B_i) \neq (A_j, B_j)$。 - 给定的图是连接的。 - 输入中的所有值都是整数。 输入 输入格式如下: $N$ $M$ $A_1$ $B_1$ $C_1$ $A_2$ $B_2$ $C_2$ $\vdots$ $A_M$ $B_M$ $C_M$ 输出 打印答案。 样例输入1 3 3 1 2 2 2 3 3 1 3 6 样例输出1 1 在删除之前,每对顶点之间的距离如下。 - 顶点$1$和顶点$2$之间的距离为$2$。 - 顶点$1$和顶点$3$之间的距离为$5$。 - 顶点$2$和顶点$3$之间的距离为$3$。 删除边$3$不会影响任何一对顶点之间的距离。在满足条件的情况下,不可能删除两条或多条边,因此答案为$1$。 样例输入2 5 4 1 3 3 2 3 9 3 5 3 4 5 3 样例输出2 0 无法删除任何边。 样例输入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 样例输出3 5

加入题单

算法标签: