#graph701. 最小生成树

最小生成树

Minimum Spanning Tree

Problem Source

BZOJ 2561

Problem Description

Given a connected undirected graph G=(V,E)G = (V, E) with positive edge weights, where n=∣V∣,m=∣E∣n = |V|, m = |E| and the nn vertices are numbered 11 through nn.

Given three positive integers u,v,L (u≠v)u, v, L\ (u \neq v). Suppose we now add an edge (u,v)(u, v) of weight LL. What is the minimum number of edges we must delete so that this new edge could appear both in a minimum spanning tree and in a maximum spanning tree of the resulting graph?

Input Format

The first line contains two numbers n,m (1≤n≤20000,0≤m≤200000)n, m\ (1 \le n \le 20000, 0 \le m \le 200000).

Each of the next mm lines contains three positive integers x,y,w (x≠y,1≤w≤20000)x, y, w\ (x \neq y, 1 \le w \le 20000), indicating an edge (x,y)(x, y) of weight ww in GG.

The last line contains three space-separated integers u,v,L (u≠v,1≤L≤20000)u, v, L\ (u \neq v, 1 \le L \le 20000).

Output Format

Output one integer: the minimum number of edges that must be deleted.

Sample Input

3 2
3 2 1
1 2 3
1 2 2

Sample Output

1