[Usaco08jan] Telephone line telephone Lines

Source: Internet
Author: User

Years later, dumb-dumb grew up and became a telephone line planner. Because the earthquake caused a city's telephone line all damaged, stupid is responsible for receiving the epicenter of the city's head. The city is surrounded by N (1<=n<=1000) of obsolete telephone poles based on 1......N sequential numbers, with no telephone line connection between any two poles, altogether P (1<=p<=10000) to the telephone pole can pull the telephone line. Other due to earthquakes make it impossible to connect.

The two end points of the first pair of Poles are ai,bi, and their distances are Li (1<=li<=1000000). Each pair (AI,BI) in the data appears only once. The telephone pole numbered 1 has been connected to the national telephone network, and the entire city's telephone line is connected to the number n telephone pole. In other words, the stupid task is simply to find a way to connect the number 1th and n poles, the rest of the telephone poles do not have to be connected to the telephone network.

The telecom company decided to support the disaster area free of charge for this city connection K to the telephone poles designated by the stupid, for those other telephone lines, which need to pay for them, the total cost depends on the length of the longest telephone line (each phone line is connected to only a pair of telephone poles). If you need to connect a phone bar that does not exceed the K pair, the payout is 0.

Would you please calculate how much you need to spend on the telephone line to guide the epicenter city at least? --by Rokua (Rokua's rare conscience translator)

https://www.luogu.org/problem/show?pid=1948

《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《 《《《《《《《《《

Two-point answer + conditional shortest path;

    • Two possible answers, that is, the side length sort that reads into, and then two points
    • For each answer run SPFA (because there is SPFA board on hand)
    • SPFA's Relaxation is spf[x[i].to]=spf[que[h]]+ (x[i].dis>ct?1:0) (CT Two-point answer, which means that if the side length is greater than the answer, let this edge occupy the company's quota)
    • If spf[n]>k, it is not possible to use the current answer as the answer (because the current answer is the answer, the occupation quota must be greater than k)

The code is as follows:

1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 structSS6 {7     intTo,next,dis;8}x[20001];9 intfirst[1001];Ten intd[10001]; One intque[10000],vis[1001],spf[1001]; A intn,pd,k,num,p; - voidBuildintFintTintdi) - { thex[++num].next=First[f]; -x[num].to=T; -x[num].dis=di; -first[f]=num; + } - voidSPFA (int,int ); + intMain () A { at     intI,j,l,r,mid; -scanf"%d%d%d",&n,&p,&k); -      for(i=1; i<=p;i++) -     { -scanf"%d%d%d",&j,&l,&d[i]); - build (J,l,d[i]); in build (L,j,d[i]); -     } toSort (d+1, d+p+1); +L=0; r=p;mid= (L+R)/2; -      while(l<R) the     { *Memset (SPF, (0x3f3f3f),sizeof(SPF)); $Pd=0;Panax NotoginsengSPFA (1, D[mid]); -         if(pd==1) the         { +R=mid; AMid= (L+R)/2; the         } +         Else -         { $L=mid+1; $Mid= (L+R)/2; -         } -     } the     if(r==p&&pd==0) d[r]=-1; -printf"%d", D[r]);Wuyi     return 0; the } - voidSPFA (intSintCT) Wu { -     intH=0, t=1, I; Aboutspf[s]=0; $que[t]=s;vis[s]=1; -      while(h<t) -     { -h++; Avis[que[h]]=0; +I=First[que[h]]; the          while(i!=0) -         { $             if(spf[x[i].to]>spf[que[h]]+ (x[i].dis>ct?)1:0)) the             { thespf[x[i].to]=spf[que[h]]+ (x[i].dis>ct?1:0); the                 if(vis[x[i].to]==0) the                 { -t++; inque[t]=x[i].to; thevis[que[t]]=1; the                 } About             } theI=X[i].next; the         } the     } +     if(spf[n]<=k) -Pd=1; the     return ;Bayi}

Wish AC

[Usaco08jan] Telephone line telephone Lines

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.