Bzoj 2324 Rescue Pikachu

Source: Internet
Author: User

2324: [ZJOI2011] Rescue Pikachu

Time Limit:10 Sec Memory limit:256 MB
submit:1440 solved:560

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 Input
3 4 2

0 1 1

1 2 1

2 3 100

0 3 1


Sample 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 10% of the data satisfies K = 1, and n = 3, the small wisdom will go alone to rescue Pikachu;


For 20% of the data to meet K≤3, and n≤20, by the small wisdom to destroy the Rockets strengthened defense, increase the number of strongholds;


For 40% of the data to meet K≤3, and n≤100, in the face of enhanced defense, small wisdom pulled a good friend small Xia and small just, together to rescue;


For the other 20% of the data to satisfy the existence of a road between any pair of positions, and for any 0≤x,y,z≤n, there is an inequality L (x,z) ≤l (x, y) + L (Y,Z) is established;


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

Problem solving: Recently review the database Review silly force, this inscribed to vomit blood, finally ac ...

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <climits>7#include <vector>8#include <queue>9#include <cstdlib>Ten#include <string> One#include <Set> A#include <stack> - #defineLL Long Long - #definePII pair<int,int> the #defineINF 0X3F3F3F3F3F3F3FLL - using namespacestd; - Const intMAXN = -; - structArc { +     intTo,next; - LL flow,cost; +Arcintx =0, LL y =0, LL z =0,intNXT =-1) { Ato =x; atFlow =y; -Cost =Z; -Next =NXT; -     } - }; -Arc e[maxn*MAXN]; in intHEAD[MAXN],P[MAXN]; - LL D[MAXN],DIS[MAXN][MAXN]; to inttot,s,t,n,m,k; + BOOL inch[MAXN]; - voidAddintUintv,ll flow,ll cost) { theE[tot] =arc (V,flow,cost,head[u]); *Head[u] = tot++; $E[tot] = arc (U,0,-cost,head[v]);Panax NotoginsengHEAD[V] = tot++; - } the BOOLSPFA () { +      for(inti =0; i < MAXN; ++i) { AD[i] =INF; theP[i] =-1; +         inch[I] =false; -     } $queue<int>Q; $D[s] =0; - Q.push (S); -      while(!Q.empty ()) { the         intU =Q.front (); - Q.pop ();Wuyi         inch[U] =false; the          for(inti = Head[u]; ~i; i =E[i].next) { -             if(E[i].flow && d[e[i].to] > D[u] +e[i].cost) { WuD[e[i].to] = D[u] +E[i].cost; -P[e[i].to] =i; About                 if(!inch[e[i].to]) { $                     inch[E[i].to] =true; - Q.push (e[i].to); -                 } -             } A         } +     } the     returnP[t] >-1; - } $ LL Solve () { theLL ans =0; the      while(SPFA ()) { the          for(inti = p[t]; ~i; i = p[e[i^1].to]) { the--E[i].flow; -++e[i^1].flow; in         } theAns + =D[t]; the     } About     returnans; the } the voidFloyd () { the      for(intK =0; K <= N; ++k) +          for(inti =0; I <= N; ++i) -              for(intj =0; J <= N; ++j) the                 if(k <= I | | k <=j)BayiDis[i][j] = min (dis[i][j],dis[i][k]+dis[k][j]); the } the intMain () { -     intu,v; - LL W; the      while(~SCANF (" %d%d%d",&n,&m,&K)) { thememset (head,-1,sizeof(head)); the          for(inti = tot =0; I <= N; ++i) the              for(intj =0; J <= N; ++j) -DIS[I][J] = i = = j?0: INF; the          for(inti = tot =0; i < M; ++i) { theCin>>u>>v>>W; theDIS[U][V] = Dis[v][u] =min (dis[u][v],w);94         } the Floyd (); theS = (n+1) <<1; theT = s|1;98          for(inti =0; I <= N; ++i) AboutAdd (i<<1,i<<1|1, 1ll,-INF); -          for(inti =0; I <= N; ++i) {101Add (i<<1|1T1,0);102              for(intj = i +1; J <= N; ++j)103Add (i<<1|1,j<<1,1, Dis[i][j]);104         } theAdd (S,1K0);106Cout<<n*inf+solve () <<Endl;;107     }108     return 0;109}
View Code

Bzoj 2324 Rescue Pikachu

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.