Description
Alice and Bob are now traveling by plane. They chose a relatively cheap airline. The airline operates in a total of NN cities, with these cities marked as 00 to n-1n-1, a total of MM routes, each connecting two cities, and there is a certain price for the route.
Alice and Bob are now switching from one city along the route to another city. Airlines offer discounts for their trip. They can fly on a maximum of KK routes for free. So how much does Alice and Bob spend on this trip?
Input/Output Format
Input Format:
The first line of the data has three integers, n, m, kN, M, and K, indicating the number of cities, routes, and free rides respectively.
The second row has two integers, namely, S, ts, and T, indicating the start and end cities of the trip respectively.
Next, there are three integers (a, B, CA, B, and C) in the M line, indicating that there is a route that can reach BB in the city from the city AA, or, the price for arriving at City AA from city BB is CC.
Output Format:
Only one row contains an integer, which is the minimum cost.
Input and Output sample input sample #1: Copy
5 6 10 40 1 51 2 52 3 53 4 52 3 30 2 100
Output example #1: Copy
8
Description
For 30% of data, 2 \ Le n \ le 50, 1 \ le m \ le 300, K = 02 ≤ n ≤ 50, 1 ≤ m ≤ 300, K = 0;
For 50% of data, 2 \ Le n \ le 600,1 \ le m \ le 6000,0 \ le k \ le 12 ≤ n ≤ 600,1 ≤ m ≤ 6000,0 ≤ k ≤ 1;
For 100% of data, 2 \ Le n \ le records, 1 \ le m \ le 50000,0 \ le k \ le 102 ≤ n ≤ limit, 1 ≤ m ≤ 50000,0 ≤ k ≤ 10 ,0 \ le s, T <n, 0 \ le a, B <n, a \ neq B, 0 \ le C \ le 10000 ≤ S, T <n, 0 ≤ a, B <n, A = B, 0 ≤ C ≤ 1000
Question
Just create a layered graph. qwq
Create k + 1 layer, where the I layer indicates that (I-1) Free tickets are used.
Each edge is created in the corresponding layer, and free edge is also created in the direction of the adjacent layer.
I feel that this graphic is very like a network stream.
1 qwerta 2 p4568 [jloi2011] Flight Route accepted 3 100 4 code C ++, 1.24kb 5 submission time 19:35:30 6 elapsed time/memory 617 ms, 26366kb 7 # include <iostream> 8 # include <cstring> 9 # include <cstdio> 10 # include <queue> 11 using namespace STD; 12 const int maxn = 10000 + 3, maxm = 50000 + 3; 13 struct EMM {14 int E, F, L; 15} A [11*4 * maxm]; 16 int H [11 * maxn]; 17 int tot = 0; 18 int N, K; 19 void con (int x, int y, int L) 20 {21 // cout <"con" <x <"" <Y <<"" <L <Endl; 22 A [++ tot]. F = H [X]; 23 h [x] = tot; 24 A [tot]. E = y; 25 A [tot]. L = L; 26 return; 27} 28 void add (int x, int y, int L) 29 {30 for (int c = 0; C <= K; + C) 31 {32 int u = x + C * n, V = Y + C * n; 33 con (u, v, L); 34 con (V, u, L); 35} 36 for (int c = 0; C <K; ++ c) 37 {38 int u = x + C * n, V = Y + (C + 1) * n; 39 con (u, v, 0); 40 u = x + (C + 1) * n, V = Y + C * n; 41 con (v, U, 0); 42} 43} 44 struct ahh {45 int nod, V; 46 }; 47 struct CMP {48 bool operator () (ahh Qaq, ahh qwq) {4 9 return Qaq. v> qwq. v; 50}; 51}; 52 priority_queue <ahh, vector <ahh>, CMP> q; 53 int d [11 * maxn]; 54 bool SF [11 * maxn]; 55 int main () 56 {57 // freopen (". in "," r ", stdin); 58 int m; 59 scanf (" % d ", & N, & M, & K); 60 int s, t; 61 scanf ("% d", & S, & T); 62 for (INT I = 1; I <= m; ++ I) 63 {64 int X, Y, L; 65 scanf ("% d", & X, & Y, & L); 66 Add (x, y, l); 67} 68 T = K * n + T; 69 // cout <S <"<t <Endl; 70 memset (D, 127, sizeof (d); 71 d [s] = 0; 72 Q. push ((Ahh) {s, 0}); 73 while (! Q. empty () 74 {75 int X; 76 do {x = Q. top (). nod; q. pop () ;}while (SF [x] &! Q. empty (); 77 SF [x] = 1; 78 for (INT I = H [X]; I; I = A [I]. f) 79 if (d [A [I]. e]> d [x] + A [I]. l) 80 {81 d [A [I]. e] = d [x] + A [I]. l; 82 Q. push (ahh) {A [I]. e, D [A [I]. e]}); 83} 84} 85 cout <D [T]; 86 return 0; 87}
"Jloi2011" "luogup4568" flight route (Shortest Path of the layered chart