POJ 2394 Dijkstra
题意:
思路:
裸的Dijkstra 爆敲一发模板
//By SiriusRen
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 2222
int f,p,c,m,xx,yy,zz,w[N],v[N],next[N],first[N],tot,dis[N],vis[N],ans,s[N];
struct Node{int now,weight;}jy;
priority_queue<Node>pq;
void add(int x,int y,int z){
w[tot]=z,v[tot]=y,next[tot]=first[x],first[x]=tot++;
}
bool operator < (Node a,Node b){
return a.weight>b.weight;
}
void Dijkstra(){
memset(dis,0x3f,sizeof(dis));
dis[1]=0;
jy.now=1,jy.weight=0;
pq.push(jy);
while(!pq.empty()){
Node t=pq.top();pq.pop();
if(vis[t.now])continue;
vis[t.now]=1;
for(int i=first[t.now];~i;i=next[i])
if(!vis[v[i]]&&dis[v[i]]>dis[t.now]+w[i]){
dis[v[i]]=dis[t.now]+w[i];
jy.now=v[i],jy.weight=dis[v[i]];
pq.push(jy);
}
}
}
int main(){
memset(first,-1,sizeof(first));
scanf("%d%d%d%d",&f,&p,&c,&m);
for(int i=1;i<=p;i++){
scanf("%d%d%d",&xx,&yy,&zz);
add(xx,yy,zz),add(yy,xx,zz);
}
Dijkstra();
for(int i=1;i<=c;i++){
scanf("%d",&xx);
if(dis[xx]<=m)
s[++ans]=i;
}
printf("%d\n",ans);
for(int i=1;i<=ans;i++)
printf("%d\n",s[i]);
}