题意:







思路:

裸的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]);
}

POJ 2394 Dijkstra的更多相关文章

  1. poj 2378 (dijkstra)

    http://poj.org/problem?id=2387 一个dijkstra的模板题 #include <stdio.h> #include <string.h> #de ...

  2. POJ 1062 ( dijkstra )

    http://poj.org/problem?id=1062 一个中文题,一个多月之前我做过,当时我是用搜索写的,不过苦于卡在无法确定等级关系,所以就错了. 看了别人的博客后,我还是不是很理解所谓的枚 ...

  3. Poj(2253),Dijkstra松弛条件的变形

    题目链接:http://poj.org/problem?id=2253 题意: 给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通 ...

  4. Poj(1797) Dijkstra对松弛条件的变形

    题目链接:http://poj.org/problem?id=1797 题意:从路口1运货到路口n,最大的运货重量是多少?题目给出两路口间的最大载重. 思路:j加到s还是接到K下面,取两者的较大者,而 ...

  5. hdu 2544 hdu 1874 poj 2387 Dijkstra 模板题

    hdu 2544  求点1到点n的最短路  无向图 Sample Input2 1 //结点数 边数1 2 3 //u v w3 31 2 52 3 53 1 20 0 Sample Output32 ...

  6. poj 2662(Dijkstra+记忆化)

    题目链接:http://poj.org/problem?id=2662 思路:首先路径的选择,如果B点到终点的距离比A点到终点的最短距离短,那么就从A走到B,换句话说,就是每次都是择优选择更靠近终点的 ...

  7. Til the Cows Come Home(poj 2387 Dijkstra算法(单源最短路径))

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32824   Accepted: 11098 Description Bes ...

  8. poj 3159 dijkstra 最短路

    Description During the kindergarten days, flymouse was the monitor of his class. Occasionally the he ...

  9. POJ 3268 (dijkstra变形)

    题目链接 :http://poj.org/problem?id=3268 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveni ...

随机推荐

  1. ListView有Header时的position情况

     问题: headerView 为第0个view,item 的 pos会从1开始. 解决方式: position减去 listView.getHeaderViewsCount().例如我想得到list ...

  2. wpf convert png to xaml

    原文:wpf convert png to xaml 把png图片转化成xaml资源 <ResourceDictionary xmlns="http://schemas.microso ...

  3. Linux Network配置

    /etc/sysconfig/network [root@mytest ~]# cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=mytest /e ...

  4. CF 420B Online Meeting 模拟题

    只是贴代码,这种模拟题一定要好好纪念下 TAT #include <cstdio> #include <cstring> #include <algorithm> ...

  5. 题解 CF383C 【Propagating tree】

    这道题明明没有省选难度啊,为什么就成紫题了QAQ 另:在CF上A了但是洛谷Remote Judge玄学爆零. 思路是DFS序+线段树. 首先这道题直观上可以对于每一次修改用DFS暴力O(n),然后对于 ...

  6. Qt 在圆形中贴图片

    void Widget::paintEvent(QPaintEvent *) { QPainter p(this); QPixmap pix(":/images/a.jpg"); ...

  7. Jeff Dean专访,有不少干货

    <专访Jeff Dean:我们要推动机器学习再上一层楼> 文件链接如下: Link https://arxiv.org/ 有意思的是,里面提到的 arXiv网站,一个能够用来证明论文上传时 ...

  8. 千千万万的IT开发project师路在何方

    已经找不到该文章的最初出处了,有找到的人请告诉我.谢谢~~ 千千万万的IT开发project师路在何方 2007-06-25 21:41 恭喜,你选择开发project师作为自已的职业! 悲哀.你选择 ...

  9. MAC 文件加密

    MAC 文件加密 (2011-10-08 00:08:52) 标签: 杂谈 分类: MAC技巧篇 我们都有一些私密的文件需要保存,在苹果操作系统下,如何为这些文件或文件夹设置密码呢? 利用系统自带的创 ...

  10. 对照 Android 的 Intent 与 iOS StoryBoard 的 Segue - Intent 假设也能添加个prepareForSegue回调就好了

    对照 Android 的 Intent 与 iOS StoryBoard 的 Segue - Intent 假设也能添加个prepareForSegue回调就好了 太阳火神的漂亮人生 (http:// ...