PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000070. Loại bỏ cạnh dư (Edge Deletion)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Loại bỏ cạnh dư (Edge Deletion)

Edge Deletion

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Given a positively weighted undirected graph, count the edges whose individual deletion does not change any all-pairs shortest distance. A replacement path of equal length is sufficient.

Input

First n,mn,m, followed by mm undirected weighted roads using 1-based vertices. Parallel roads may occur and are treated as separate edges.

Output

Print the number of individually removable edges.

Subtasks

  • Subtask 1 (40 points): 2≤n≤72\le n\le 7. 0≤m≤10000\le m\le1000, 1≤w≤1061\le w\le10^6; mỗi cạnh có chỉ số riêng, cho phép cạnh song song.

  • Subtask 2 (60 points): 2≤n≤352\le n\le 35. 0≤m≤10000\le m\le1000, 1≤w≤1061\le w\le10^6; mỗi cạnh có chỉ số riêng, cho phép cạnh song song.

Examples

Input

3 3
1 2 2
2 3 3
1 3 5

Output

1

Explanation

The direct edge 1–3 of weight 5 can be replaced by the two-edge path of weight 2+3=5. Removing this edge preserves every distance.