The problem is to let you find the S-point to the T-point K short, using a * search, the search uses two indicator functions H g, h represents the shortest path from the source point to the current point, and the G-point indicates the shortest path from the current point to the sink point, and the h at the time of the search for the K-vertex is the length of the K-short, the code is as follows:
#include <cstdio>#include<cstring>#include<algorithm>#include<queue>#include<vector>using namespacestd;Const intMAXN = ++Ten;intN, M;intS, T, K;structEdge {intV, c;}; Vector<edge> G[MAXN];//Forward EdgeVector<edge> P[MAXN];//Reverse EdgeintG[MAXN];//solve the value of the H functionstructdij{intu, c; BOOL operator< (ConstDIJ&R)Const { returnC>r.c; }};BOOLVIS[MAXN];voidDijkstraints) {memset (g,0x3f,sizeof(g)); G[s]=0; memset (Vis,0,sizeof(VIS)); Priority_queue<Dij>que; Que.push ((DIJ) {s,0}); while(!Que.empty ()) {DIJ TP=que.top (); Que.pop (); intu=tp.u; if(Vis[u])Continue; Vis[u]=1; for(intI=0; I<p[u].size (); i++) { intv = p[u][i].v, cost =p[u][i].c; if(G[v] > g[u]+Cost ) {G[v]= g[u]+Cost ; Que.push ((DIJ) {V, g[v]}); } } }}structastar{inth, G, u; BOOL operator< (Constastar& R)Const { returnH+g > r.h+R.G; }};intTIMES[MAXN];intAstar () {memset (Times,0,sizeof(times)); Priority_queue<Astar>que; Que.push ((Astar) {0, G[s], S}); if(S = = T) k++; while(!Que.empty ()) {Astar TP=que.top (); Que.pop (); intU =tp.u; Times[u]++; if(Times[u]==k && u==t)returnTp.h; Else if(Times[u] > K)Continue; for(intI=0; I<g[u].size (); i++) { intv = g[u][i].v, c=g[u][i].c; Que.push ((Astar) {tp.h+c, G[v], v}); } } return-1;}intMain () {scanf ("%d%d", &n, &M); for(intI=0; i<m; i++) { intu, V, t; scanf ("%d%d%d", &u, &v, &t); G[u].push_back (Edge) {V, t}); P[v].push_back (Edge) {u, t}); } scanf ("%d%d%d", &s, &t, &j); Dijkstra (T); intres =Astar (); printf ("%d\n", RES); return 0;}
poj2449 k Short Circuit problem