The shortest, and then can have multiple free opportunities, not difficult to write, but the shortest possible time to try to write with the pointer really fast point, a start to see the wrong data range array open too big tle;
----------------------------------------------------------------------------------------------
#include <cstdio>
#include <cstring>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace Std;
#define REP (i,n) for (int i=1;i<=n;i++)
#define CLR (x,c) memset (x,c,sizeof (x))
#define ADDE (u,v,w) Add (u,v,w), add (v,u,w)
int read () {
int x=0;
Char C=getchar ();
int f=1;
while (!isdigit (c)) {
if (c== '-') f=-1;
C=getchar ();
}
while (IsDigit (c)) {
x=x*10+c-' 0 ';
C=getchar ();
}
return x*f;
}
struct edge{
int to,d;
Edge*next;
};
EDGE*PT,EDGES[50005*2];
EDGE*HEAD[10005];
int n,m,k,s,t;
int dis[10005][15];
struct node{
int x,k,d;
Node (int _x,int _k,int _d): X (_x), K (_k), D (_d) {};
BOOL operator< (const NODE&RHS) const{
return D>RHS.D;}
};
priority_queue<node>q;
void Add (int u,int v,int W) {
pt->to=v;
pt->d=w;
pt->next=head[u];
head[u]=pt++;
}
void Dijkstra () {
CLR (dis,0x3f);
CLR (dis[s],0);
Q.push (Node (s,0,0));
Rep (I,k)
Q.push (Node (s,i,0));
while (!q.empty ()) {
Node O=q.top ();
Q.pop ();
if (O.D!=DIS[O.X][O.K]) continue;
for (Edge*e=head[o.x];e;e=e->next) {
int to=e->to;
if (DIS[O.X][O.K]+E->D<DIS[TO][O.K]) {
dis[to][o.k]=dis[o.x][o.k]+e->d;
Q.push (Node (TO,O.K,DIS[TO][O.K));
}
if (dis[o.x][o.k]<dis[to][o.k+1]&&o.k<k) {
DIS[TO][O.K+1]=DIS[O.X][O.K];
Q.push (Node (to,o.k+1,dis[to][o.k+1));
}
}
}
}
int main () {
/*freopen ("Test.in", "R", stdin);
Freopen ("Test.out", "w", stdout); */
scanf ("%d%d%d%d%d", &n,&m,&k,&s,&t);
s++,t++;
CLR (head,0);
Pt=edges;
Rep (i,m) {
int U=read (), V=read (), W=read ();
u++,v++;
Adde (U,V,W);
}
/*rep (i,n) {
printf ("%d\n", I);
for (Edge*e=head[i];e;e=e->next) {
printf ("%d%d\n", e->to,e->d);
}
}*/
Dijkstra ();
int ans=dis[t][0];
Rep (i,k) {
Ans=min (Ans,dis[t][i]);
}
printf ("%d\n", ans);
Fclose (stdin); fclose (stdout);
return 0;
}
----------------------------------------------------------------------------------------------
2763: [JLOI2011] Flight route time Limit:10 Sec Memory limit:128 MB
submit:1448 solved:551
[Submit] [Status] [Discuss] Descriptionalice and Bob are now travelling by air, and they have opted for a relatively cheap airline. The airline operates in a total of N cities, which are marked as 0 to n-1, with a total of M routes, two cities per route, and a certain price on the route. Alice and Bob are now moving from one city to another, on the way to a different city. Airlines also offer discounts on their trip, and they can fly on up to K routes for free. So how much does Alice and Bob spend at least for this trip? The first line of the input data has three integers, n,m,k, indicating the number of cities, routes, and free rides. The second line has two integers, s,t, which represent the starting city number and the destination city number for each of their trips. (0<=s,t<n) Next there are m lines, three integers per line, a,b,c, indicating the existence of a route, which can be reached from city A to City B, or from City B to city A, with a price of C. (0<=a,b<n,a and B are unequal, 0<=c<=1000) Output has only one row and contains an integer, which is the minimum cost. Sample INPUT5 6 1
0 4
0 1 5
1 2 5
2 3 5
3 4 5
2 3 3
0 2 100Sample Output8hint
For 30% data ,2<=n<=50,1<=m<=300,k=0;
For 50% data ,2<=n<=600,1<=m<=6000,0<=k<=1;
For 100% data , 2<=n<=10000,1<=m<=50000,0<=k<=10.
Source [Submit] [Status] [Discuss]
bzoj2763: Shortest circuit