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]);
}
POJ 2394 Dijkstra的更多相关文章
- poj 2378 (dijkstra)
http://poj.org/problem?id=2387 一个dijkstra的模板题 #include <stdio.h> #include <string.h> #de ...
- POJ 1062 ( dijkstra )
http://poj.org/problem?id=1062 一个中文题,一个多月之前我做过,当时我是用搜索写的,不过苦于卡在无法确定等级关系,所以就错了. 看了别人的博客后,我还是不是很理解所谓的枚 ...
- Poj(2253),Dijkstra松弛条件的变形
题目链接:http://poj.org/problem?id=2253 题意: 给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通 ...
- Poj(1797) Dijkstra对松弛条件的变形
题目链接:http://poj.org/problem?id=1797 题意:从路口1运货到路口n,最大的运货重量是多少?题目给出两路口间的最大载重. 思路:j加到s还是接到K下面,取两者的较大者,而 ...
- 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 ...
- poj 2662(Dijkstra+记忆化)
题目链接:http://poj.org/problem?id=2662 思路:首先路径的选择,如果B点到终点的距离比A点到终点的最短距离短,那么就从A走到B,换句话说,就是每次都是择优选择更靠近终点的 ...
- Til the Cows Come Home(poj 2387 Dijkstra算法(单源最短路径))
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32824 Accepted: 11098 Description Bes ...
- poj 3159 dijkstra 最短路
Description During the kindergarten days, flymouse was the monitor of his class. Occasionally the he ...
- POJ 3268 (dijkstra变形)
题目链接 :http://poj.org/problem?id=3268 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveni ...
随机推荐
- PostgreSQL Replication之第四章 设置异步复制(7)
4.7 冲突管理 在PostgreSQL中,流复制数据仅在一个方向流动.XLOG由master提供给几个slave,这些slave消耗事务日志并为您提供一个较好的数据备份.您可能想知道这怎么会导致冲突 ...
- UI Framework-1: Aura
Aura (obsolete) This document is still good for a high level overview, with contact information, but ...
- iOS开发—— Couldn't add the Keychain Item
报错:*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn ...
- idea+spring4+springmvc+mybatis+maven实现简单增删改查CRUD
在学习spring4+springmvc+mybatis的ssm框架,idea整合简单实现增删改查功能,在这里记录一下. 原文在这里:https://my.oschina.net/finchxu/bl ...
- iostat---监视磁盘CPU相关信息
iostat命令被用于监视系统输入输出设备和CPU的使用情况.它的特点是汇报磁盘活动统计情况,同时也会汇报出CPU使用情况.同vmstat一样,iostat也有一个弱点,就是它不能对某个进程进行深入分 ...
- HDFS文件系统上传时序图 PB级文件存储时序图
自己设计的时序图. 来自为知笔记(Wiz)
- nyoj 1104 just for you
just for you 时间限制:1000 ms | 内存限制:65535 KB 难度:0 描写叙述 今天tlp和ly想去看电影了到了电影院才发现买票的人特别多 .ly不想让tlp等着急了,就先 ...
- Unix网络编程之环境搭建
环境搭建 在尝试UNP书上的样例时,会由于找不到"unp.h"等问题无法编译成功.因此在学习之前须要先搭建好编译环境. 步骤 <1>下载 UNIX网络编程源码unpv ...
- webpack03
index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- 理解Linq查询
using System; using System.Linq; static class Program { static double Square(double n) { Console.Wri ...