http://www.lydsy.com/JudgeOnline/problem.php?id=4326
Title Description
In the 2044 A.D., humans entered the cosmic era.
The state-owned planet, and a two-way waterway, each channel is built between two planets, this waterway connects all the countries of the planet.
Small in charge of a logistics company, the company has a number of transport plans, each transport plan, such as: there is a logistics spacecraft from the planet to fly along the fastest spacecraft to the planet. Obviously, it takes time for the ship to sail through a fairway, and for the fairway, the time it takes for any spacecraft to pass through it, and no interference between any two ships.
In order to encourage scientific and technological innovation, the King agreed that small logistics companies participating in the country's waterway construction, that allows a small channel to transform the adult hole, the spacecraft drove through the worm hole does not consume time. Before the construction of the wormhole was completed, the small logistics company was pre-connected with a transport plan. Upon completion of the wormhole construction, the transport plan will begin at the same time, with all the ships departing together. When the transportation plan is completed, the small logistics company's stage work is completed. If the small can freely choose which channel to transform adult hole, try to find out the small logistics company to complete the phased work of the shortest time required is how much?
Input format
The first line consists of two positive integers representing the number of planets in the country and the number of pre-planned transport plans for small companies, from 1 to numbered planets. The next line describes the construction of the waterway, where the line contains three integers and indicates that the first two-way waterway is constructed between the two planets and the time it takes for any spacecraft to sail past it. Data assurance. The next line describes the situation of the transport plan, where line contains two positive integers and indicates that the first transport plan is from planet number to planet.
Output format
The output file contains only an integer representing the minimum time required for a small logistics company to complete a phased operation.
Input sample
6 3
1 2 3
1 6 4
3 1 7
4 3 6
3 5 5
3 6
2 5
4 5
Output sample
11
Data range
Exercises
Two-part path intersection
Use to find out the length of each path, the two-point answer, for all paths of the path must be deleted at least one edge, the best solution must be to delete the longest side of the intersection of these paths, that is, the path is the longest side.
Consider how to find the path intersection: The number of paths that represent the point to which the edge passes, and the sum of all, if any, from the path to the line.
#include <iostream>#include<cstdlib>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<stack>#defineDepth 21#defineN 300005using namespacestd;intN,m,tot,ans;intanc[n][ A],a[n],b[n],d[n],lca[n],last[n],dep[n],fa[n],sum[n],v[n],dis[n];stack<int>s;structhh{intTo,next,w;} E[n<<1];intRead () {intret=0;CharC=GetChar (); while(!isdigit (c)) c=GetChar (); while(IsDigit (c)) {ret= (ret<<1) + (ret<<3) +c-'0'; c=GetChar ();} returnret;}voidAddintFrintTo,intW) {e[++tot].to=to ; E[TOT].W=W; E[tot].next=LAST[FR]; LAST[FR]=tot;}voidBFsintroot) { intI,j,now; S.push (root); Dep[root]=1; for(i=0; i<=depth;i++) Anc[root][i]=Root; while(!S.empty ()) { Now=s.top (); S.pop (); if(now!=root) for(i=1; i<=depth;i++) Anc[now][i]=anc[anc[now][i-1]][i-1]; for(i=last[now];i;i=e[i].next)if(!Dep[e[i].to]) {Dep[e[i].to]=dep[now]+1; anc[e[i].to][0]=Now ; Fa[e[i].to]=now; v[e[i].to]=E[I].W; Dis[e[i].to]=dis[now]+E[I].W; S.push (e[i].to); } }}voidSwimint&x,inth) { inti; for(i=0; h;i++) { if(h&1) x=Anc[x][i]; H/=2; }}intGet_lca (intXinty) { inti; if(dep[x]>Dep[y]) swap (x, y); if(Dep[x]!=dep[y]) swim (y,dep[y]-dep[x]); if(x==y)returnx; while(true) { for(i=0; anc[x][i]!=anc[y][i];i++); if(i==0)returnanc[x][0]; I--;x=anc[x][i];y=Anc[y][i]; } }voidWorkintNow ) { inti,j; for(i=last[now];i;i=e[i].next)if(e[i].to!=Fa[now]) {work (e[i].to); Sum[now]+=Sum[e[i].to]; }}BOOLCheckintLim) { intI,j,cnt=0, t=0; for(i=1; i<=n;i++) sum[i]=0; for(i=1; i<=m;i++) if(d[i]>Lim) {cnt++; T=max (t,d[i]-Lim); Sum[a[i]]++;sum[b[i]]++; Sum[lca[i]]-=2; } Work (1); for(i=1; i<=n;i++) if(sum[i]==cnt&&v[i]>=t)return true; return false; }intMain () {intI,j,u,v,w,l,r,mid; N=read (); m=read (); for(i=1; i<=n-1; i++) {u=read (); V=read (); w=read (); Add (u,v,w); add (v,u,w); } BFS (1); for(i=1; i<=m;i++) {A[i]=read (); b[i]=read (); Lca[i]=Get_lca (A[i],b[i]); D[i]=dis[a[i]]+dis[b[i]]-(dis[lca[i]]<<1); } l=0, r=d[1]; for(i=2; i<=m;i++) r=Max (r,d[i]); Ans=99999999; while(l<=r) {Mid= (l+r) >>1; if(Check (mid)) Ans=min (Ans,mid), r=mid-1; ElseL=mid+1; } printf ("%d", ans); return 0;}
"Bzoj 4326" NOIP2015 Transport Plan