3336 Telephone Network (two points + shortest circuit)time limit: 1 sspace limit: 32000 KBtitle level: Golden GoldTitle Description
Description
Because the earthquake makes the connection Wenchuan County telephone line all damage, if you are responsible for the telephone line to the epicenter of Wenchuan County City, the head of the Wenchuan county around the distribution of N (1≤n≤1,000) root by 1..N serial number of discarded telephone pole, any two telephone line rod between no telephone line connected. Altogether P (1≤p≤10,000) to the telephone line rod can pull the telephone line, the rest because of the earthquake makes unable to be connected.
The two endpoints of the telephone pole are ai,bi, and the distance between them is Li (1≤li≤1,000,000). Each pair (AI,BI) is guaranteed to appear at most 1 times in the data. Number 1 of the telephone pole has been a pick up the country's telephone network, the entire county's telephone line is connected to the number of the telephone line N. In other words, your task is simply to find a path that connects the 1th and N telephone poles, and the rest of the phone poles do not necessarily have to connect to the telephone network.
The telecom company decided to support the disaster area free for Wenchuan County link K (0≤k<n) to the telephone pole specified by you. For those phone lines that are in addition, you need to pay for them, and the total cost equals the length of the longest phone line (each phone line is connected to only a pair of phone poles). If the number of telephone poles to be connected does not exceed the K pair, then the total expenditure is 0.
Would you please calculate how much you need to spend on the telephone line to get the telephone line to the epicenter of Wenchuan County?
Enter a description
Input Description
The first line of the input file contains three integers separated by spaces: N,p and K.
The second line to line p+1: integers separated by spaces for each line: Ai,bi and Li.
Output description
Output Description
The output file contains only an integer representing the minimum expenditure on this project. If the task cannot be completed, then output-1.
Sample input
Sample Input
5 7 1
1 2 5
3 1 4
2 4 8
3 2 3
5 2 9
3 4 7
4 5 6
Sample output
Sample Output
4
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <queue>5 6 #defineN 1000000+207 8 using namespacestd;9 Ten intN,m,k,num,head[n]; One BOOLInq[n]; A intDis[n]; - structnode - { the intU,v,t,pre; - }a[n]; - - voidAdd_tree (int,int,int); + voidSPFA (int); - voidinit (); + A intMain () at { - init (); - intL=0, r=n,ans=-1; - while(l<=R) - { -memset (INQ,0,sizeof(INQ)); inmemset (DIS,127/3,sizeof(DIS)); - intMid= (L+R)/2; to SPFA (mid); + if(dis[n]<=k) - { theans=mid; *r=mid-1; $ }Panax Notoginseng Else -L=mid+1; the } +printf"%d", ans); A return 0; the } + - voidAdd_tree (int from,intTo,intll) $ { $num++; -a[num].u= from; -a[num].v=to ; thea[num].t=ll; -a[num].pre=head[ from];Wuyihead[ from]=num; the } - Wu voidSPFA (ints) - { Aboutqueue<int>Q; $dis[1]=0; -inq[1]=0; -Q.push (1); - while(!q.empty ()) A { + intp=Q.front (); the Q.pop (); -inq[p]=0; $ for(intI=head[p];i;i=a[i].pre) the { the intsi; the if(a[i].t<=s) theSi=0; - Else inSi=1; the if(dis[a[i].v]>dis[p]+si) the { Aboutdis[a[i].v]=dis[p]+si; the if(inq[a[i].v]==0) the { the Q.push (A[I].V); +inq[a[i].v]=1; - } the }Bayi } the the } - } - the voidInit () the { thescanf"%d%d%d",&n,&m,&k); the for(intI=1; i<=m;i++) - { the intx, y, z thescanf"%d%d%d",&x,&y,&z); the add_tree (x, y, z);94 Add_tree (y,x,z); the } the}
Codevs 3336 Telephone Network