POJ 2394 Dijkstra
2024-10-01 17:15:31
题意:
思路:
裸的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]);
}
最新文章
- 黄聪:C#中HtmlAgilityPack判断是否包含或不包含指定的属性或值
- CentOS下vm虚拟机桥接联网
- IOS, xib和storyboard的混用
- .NET跨平台:再见dnx,你好dotnet cli
- 数据块损坏(block corruption)
- SQL 基础语法(创建表空间、用户、并授予权限、数据的增删改查) --(学习笔记)[转]
- 设计模式之Composite(组合)模式
- 原生JS取代一些JQuery方法
- 32位Windows7上8G内存使用感受+xp 32位下使用8G内存 (转)
- 解决 VirtualBox 安装windows 8.1 Preview OR Server 2012 R2 Preview 错误
- perl 类里的函数调用其他类的函数
- POJ 2182/暴力/BIT/线段树
- html 设置页脚div一直在页面底部
- Ionic start 创建项目报错 Error with start undefined
- React Starter Kit 中文文档
- D. How many trees? DP
- [WP]BugkuCtf - pwn2
- 【Android基础】利用Intent在Activity之间传递数据
- 【TensorFlow】基于ssd_mobilenet模型实现目标检测
- BZOJ.3575.[HNOI2014]道路堵塞(最短路 动态SPFA)
热门文章
- 【DNN 系列】 MVC 分页
- 程序Yuan,eclipse你,会用吗?
- mac、windows如何强制关闭tomcat进程
- [POI2011]MET-Meteors 整体二分_树状数组_卡常
- Could not create connection to database server. Attempted reconnect 3 times. Giving up.错误
- 基于CC2530的ZigBee转以太网网关的设计与实现
- 使用ssh过程中对数据库进行update时报错
- Intellij Idea创建的第一个JavaWeb程序
- js插件---瀑布流Masonry
- Python3小白初体验