Bzoj 2324 [ZJOI2011] Rescue Pikachu (Floyd, Fee stream)

Source: Internet
Author: User

2324: [ZJOI2011] Rescue Pikachu time Limit:10 Sec Memory limit:256 MB
submit:1777 solved:712
[Submit] [Status] [Discuss] Description

Pikachu was robbed by the Rockets with evil tricks! These three bad guys back to little wisdom left the red fruit of the provocation! For Pikachu, but also for justice, Xiao Zhi and his friends are incumbent on the road to rescue Pikachu.

The Rockets have a total of n positions, there is a two-way road between the stronghold. Positions are numbered from 1 to N, respectively. A small-wisdom line of k people from the real New town, to rescue the stranded in the N stronghold of Pikachu. For the sake of convenience, we regard the real new town as the No. 0 stronghold, at the beginning of the K-Individuals at point 0 .

Due to the heavy arming of the rockets, to destroy the K stronghold, the 1 to K-1 Point must be destroyed in sequence, and if the K-1 is not destroyed, as the defensive chain, the small intelligence line any one to enter the stronghold K, will be found, and have serious consequences. Therefore, no one is allowed to pass the K-point until the K-1 is destroyed.

In order to simplify the problem, we ignore the battle link, the small intelligence line any one person passes through the K point point to think that the K stronghold is destroyed. The destroyed stronghold can still be passed through.

K individuals can split up, as long as any one of the K-1 stronghold was destroyed, after the K-point, the K stronghold was destroyed. Obviously, if the N point is destroyed, Pikachu will be saved.

The road in the wild is unsafe, so the small wisdom line hopes to save Pikachu at the time of the destruction of N points, making the length of the road passed by the K-man the fewest sum.

Please help Xiao Zhi design a best rescue plan!

Input

The first line consists of three positive integer n,m,k. There are a total of n+1 locations, numbered from 0 to N, and M-no edges. At the beginning of the small wisdom line total K individuals are located at point 0 .

Next M line, three non-negative integers per line, the integer of line I is ai,bi,li. Represents a road that has a length of Li from the AI point to the bi point.

Output

contains only one integer S, the smallest sum of roads required to rescue Pikachu.

Sample INPUT3 4 2
0 1 1
1 2 1
2 3 100
0 3 1Sample Output3
"Sample description"
Little wisdom and small Xia went to rescue Pikachu. In the best plan, Xiao Zhi first from the real new town to the 1th point, and then to the No. 2nd stronghold. After Xiao Zhi successfully destroyed the 2nd stronghold, Xiao Xia from the real new town to go directly to the 3rd stronghold, rescued Pikachu. HINT

For 100% of the data to meet n≤150, M≤20 000, 1≤k≤10, Li≤10 000, to ensure that small wisdom line will be able to rescue Pikachu. As for why k≤10, you can think of the end in the small wisdom of the call, small wisdom, small xia, small just, small build, small remote, Xiao Sheng, Xiao Guang, Alice, Tian Tong, as well as travel to Japan, the Black Cat Sheriff, together to the war rockets.

Source

Day2

Ideas

floyd+ cost flow.

Subject conditions: 1 each point must pass, 2 through J must have passed 0. J-1

Using Floyd to find the shortest distance between points, the conversion to DAG is guaranteed condition 2. Do not exceed the coverage path of K on the DAG.

Composition: Each point establishes an XY node, a hyphen (s,0,k,0) (s,xi,1,0) (yi,t,1,0), and if there is an edge between i,j on the Dag, The Edge (Xi,yj,1,d[i][j]).

Code

1#include <cstdio>2#include <cstring>3#include <queue>4#include <vector>5 #definefor (A,B,C) for (int a= (b); a<= (c); a++)6 using namespacestd;7 8typedefLong LongLL;9 Const intMAXN = -+Ten;Ten Const intINF =1e9; One  A structedge{intU,v,cap,flow,cost; - }; - structzkw { the     intn,m,s,t; -     intVIS[MAXN],D[MAXN]; -vector<int>G[MAXN]; -Vector<edge>es; +      -     voidInitintN) { +          This->n=N; A es.clear (); at          for(intI=0; i<n;i++) g[i].clear (); -     } -     voidAddedge (intUintVintCapintCost ) { -Es.push_back (Edge) {u,v,cap,0, cost}); -Es.push_back (Edge) {v,u,0,0,-Cost }); -m=es.size (); inG[u].push_back (M-2); -G[v].push_back (M-1); to     } +     BOOLSPFA () { -memset (Vis,0,sizeof(Vis)); the          for(intI=0; i<n;i++) d[i]=INF; *queue<int>Q; $d[t]=0, vis[t]=1, Q.push (t);Panax Notoginseng          while(!Q.empty ()) { -             intU=q.front (); Q.pop (), vis[u]=0; the              for(intI=0; I<g[u].size (); i++) { +edge& e=Es[g[u][i]]; A                 intv=e.v; the                 if(es[g[u][i]^1].cap && d[v]>d[u]-e.cost) { +d[v]=d[u]-E.cost; -                     if(!Vis[v]) { $vis[v]=1; $ Q.push (v); -                     } -                 } the             } -         }Wuyi         returnd[s]!=INF; the     } -     intDfsintUinta,ll&Cost ) { Wuvis[u]=1;if(u==t)returnA; -         intUsed=0, W; About          for(intI=0; I<g[u].size (); i++) { $edge& e=Es[g[u][i]]; -             intv=e.v; -             if(D[u]-e.cost==d[v] &&!vis[v] &&e.cap) { -W=dfs (V,min (A-used,e.cap), cost); Acost+=w*E.cost; +E.cap-=w, es[g[u][i]^1].cap+=W; theUsed+=w;if(used==a)returnA; -             } $         } the         returnused; the     } the     intMincost (intSintt,ll&Cost ) { the          This->s=s, This->t=T; -         intflow=0; cost=0; in          while(SPFA ()) { thevis[t]=1; the              while(Vis[t]) { Aboutmemset (Vis,0,sizeof(Vis)); theflow+=DFS (s,inf,cost); the             } the         } +         returnflow; -     } the } MC;Bayi  the intn,m,k; the intD[MAXN][MAXN]; -  - intMain () { thescanf"%d%d%d",&n,&m,&K); theMc.init (n+n+4); the     ints=n+n+2, t=s+1; the     intu,v,w; -for (I,0, N) for (J,0, N) d[i][j]=INF; thefor (I,1, M) { thescanf"%d%d%d",&u,&v,&W); theD[u][v]=d[v][u]=min (D[U][V],W);//Heavy Edge94     } theFor (K,0, n) for (I,0, N) for (J,0, N) the         if(K<=j | | k<=i) d[i][j]=min (d[i][k]+d[k][j],d[i][j]); theMc. Addedge (s,n+1K0);98for (I,1, N) { AboutMc. Addedge (s,i+n+1,1,0); -Mc. Addedge (I,t,1,0);101     }102for (I,0, n) for (j,i+1, N)103         if(D[i][j]!=inf) MC. Addedge (i+n+1J1, D[i][j]);104 LL cost; the MC. Mincost (s,t,cost);106printf"%lld", cost);107     return 0;108}

Bzoj 2324 [ZJOI2011] Rescue Pikachu (Floyd, Fee stream)

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.