Time limit of the King's troubles: theMs | Memory Limit:65535KB Difficulty:2
-
-
Describe
-
      c Country by n small islands, in order to facilitate contact between the island, c the country has established m Bridge in the small island, Each bridge connects two small islands. There may be multiple bridge connections between the two islets. However, due to the erosion of seawater, some bridges are at risk of being unable to be used. If all the bridges between the two islets are not available, then the two islands cannot be reached directly. However, as long as the residents of these two islands can pass other bridges or other The island arrives at each other and they will be safe." However, if there is a way between the two small islands the previous day and the latter cannot be reached, the residents will protest together.
Now the king of C has known the number of days each bridge can use, beyond which the number of days cannot be used. Now he wants to know how many protests the residents are going to launch.
-
-
Input
-
-
multiple sets of test data.
Enter two positive integers n and m first for each set of data.
Next m line, each line three integers a, B, t, respectively, that the bridge connects A and B two small islands, can use T-day. The number of islets is incremented from 1 onwards. (1≤n≤10000,1≤m≤100000,1<=a,b<=n,1≤t≤100000)
-
-
Output
-
-
output An integer that indicates the number of protests the residents have initiated.
-
-
Sample input
-
-
4 41 2 21 3 22 3 13 4 3
-
-
Sample output
-
-
2
-
-
Tips
-
-
For example:
The first day after the bridge between 2 and 3 can not be used, does not affect.
After the second day between 1 and 2, and the bridge between 1 and 3 is not available, residents will protest.
Third days after the bridge between 3 and 4 is not available, residents will protest.
-
-
Source
-
-
Blue Bridge Cup
-
-
Uploaded by
-
-
TC_ Li Yuanhai AC Code
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include < Algorithm>using namespace Std;struct s{int u,v,w;} Edge[100100];int pre[100100],a[100010];void init (int n) {int i;for (i=0;i<=n;i++) pre[i]=i;} int CMP (s a,s b) {return A.W>B.W;} int find (int x) {if (x==pre[x]) return Pre[x];return pre[x]=find (pre[x]);} int main () {int n,m;while (scanf ("%d%d", &n,&m)!=eof) {int i;init (n); for (i=0;i<m;i++) {scanf ("%d%d%d",& EDGE[I].U,&EDGE[I].V,&EDGE[I].W);} Sort (edge,edge+m,cmp); int ans=0,cnt=0;for (i=0;i<m;i++) {int fa=find (EDGE[I].U); int fb=find (EDGE[I].V); if (FA!=FB ) {PRE[FA]=FB;A[CNT++]=EDGE[I].W;}} Ans=unique (a,a+cnt)-a;printf ("%d\n", ans);}
Nyoj Topic 925 King's Annoyance (minimum spanning tree variant)