A*启发式搜索
(poj2449)
int n,k,Start,End;
int dis[maxn]; // 存放每个点到终点的最短距离
bool vis[maxn];
struct heap{
int p,d;
heap(int _p,int _d):p(_p),d(_d){}
bool operator < (const heap &x) const{
return d+dis[p] > x.d+dis[x.p]; // d在反向dij里没有用,在A*函数里为该点到起点的距离(不一定是最短距离!!!)
}
};
/// ↓构图↓
int head[maxn],rhead[maxn]; // 构反向图是为了求出每个点到终点的最短距离
struct Edge{
int from,to,cost;
int next,rnext;
}e[100005];
int edgenum=0;
void addEdge(int from,int to,int cost){
e[edgenum].from=from;
e[edgenum].to=to;
e[edgenum].cost=cost;
e[edgenum].next=head[from];
head[from]=edgenum;
e[edgenum].rnext=rhead[to];
rhead[to]=edgenum;
edgenum++;
}
///
void dij(int s){
priority_queue<heap> q;
memset(dis,INF,sizeof(dis));
dis[s]=0;
q.p