#P5934. [清华集训 2012] 最小生成树

    ID: 6695 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2012网络流最小割CTT(清华集训/北大集训)

[清华集训 2012] 最小生成树

Problem Description

Given a connected undirected graph G=(V,E)G=(V,E) with positive edge weights, where N=VN=|V| and M=EM=|E|. The NN vertices are numbered from 11 to NN. Given three positive integers u,vu, v and LL (uv)(u \ne v), suppose we now add an edge (u,v)(u, v) with weight LL. What is the minimum number of edges that must be deleted so that this edge can appear in some minimum spanning tree, and can also appear in some maximum spanning tree?

Input Format

The first line contains two integers separated by spaces, which are NN and MM.

The next MM lines each contain three positive integers u,vu, v and ww, indicating that in graph GG there is an edge between uu and vv with weight ww.

The last line contains three integers separated by spaces, which are u,vu, v and LL.

The testdata guarantees that there are no self-loops in the graph.

Output Format

Output one line with one integer, indicating the minimum number of edges that need to be deleted.

3 2
3 2 1
1 2 3
1 2 2

1

Hint

Sample Explanation

We only need to delete edge (1,2)(1,2). After deleting it and adding the new edge, the spanning tree of the graph becomes unique.

Constraints

For 20%20\% of the testdata, N10,M20,L20N\leqslant10, M\leqslant20, L\leqslant20.

For 50%50\% of the testdata, N300,M3000,L200N\leqslant300, M\leqslant3000, L\leqslant200.

For 100%100\% of the testdata, N20000,M200000,L20000N\leqslant20000, M\leqslant200000, L\leqslant20000.

Translated by ChatGPT 5