POJ Remmarguts' Date


题解:
次短路模板。
代码:
#include<cstdio>
#include<iostream>
using namespace std;
#define inf 1e9
#define N 100005
#define S1 dis[x]+e[i].v
#define S2 sdis[x]+e[i].v
using namespace std;
struct node {
int to,next,v;
} e[N<<];
int head[N],cnt;
void insert(int x, int y, int v) {
e[++cnt].to=y;
e[cnt].next=head[x];
e[cnt].v=v;
head[x]=cnt;
}
int n,m,dis[N],sdis[N],q[N<<];
bool inq[N];
void SPFA() {
for(int i=; i<=n; i++)dis[i]=sdis[i]=inf;
dis[]=;
q[]=inq[]=;
int l=,r=,t;
while (l<r) {
int x=q[l++];
for (int i=head[x]; i; i=e[i].next) {
t=e[i].to;
if (dis[t]>S1) {
sdis[t]=dis[t];
dis[t]=S1;
if (!inq[t])inq[t]=,q[r++]=t;
}
if (dis[t]<S1&&sdis[t]>S1) {
sdis[t]=S1;
if (!inq[t])inq[t]=,q[r++]=t;
}
if (sdis[t]>S2) {
sdis[t]=S2;
if (!inq[t])inq[t]=,q[r++]=t;
}
}
inq[x]=;
}
}
int main() {
cin>>n>>m;
for (int i=,x,y,v; i<=m; i++) {
cin>>x>>y>>v;
insert(x,y,v);
insert(y,x,v);
}
SPFA();
cout<<sdis[n];
return ;
}
spfa
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cstdlib>
const int MAX = ;
const int INF = 0x7fffffff;
using namespace std;
struct Edge {
int num,len;
bool operator <(const Edge &a)const {
return a.len < len;
}
}temp;
int u[MAX],v[MAX],w[MAX],dis[MAX],second[MAX],first[MAX / ],next[MAX],n,r;
void dijkstra() {
priority_queue<Edge> que;
dis[] = ;
second[] = INF;
for(int i = ; i < n; i++) dis[i] = second[i] = INF;
temp.len = temp.num = ;
que.push(temp);
while(!que.empty()) {
Edge head = que.top();
que.pop();
if(head.len > second[head.num]) continue;
int k = first[head.num];
while(k != -) {
int d = head.len + w[k];
if(dis[v[k]] > d) {
swap(dis[v[k]], d);
temp.len = dis[v[k]];
temp.num = v[k];
que.push(temp);
}
if(dis[v[k]] < d && second[v[k]] > d) {
second[v[k]] = d;
temp.len = second[v[k]];
temp.num = v[k];
que.push(temp);
}
k = next[k];
}
}
}
int main() {
scanf("%d%d",&n,&r);
memset(first, -, sizeof(first));
for(int i = ; i < r; i++) {
scanf("%d%d%d",&u[i],&v[i],&w[i]);
u[i]--,v[i]--,next[i] = first[u[i]],first[u[i]] = i,u[i + r] = v[i];
v[i + r] = u[i],w[i + r] = w[i],next[i + r] = first[u[i + r]],first[u[i + r]] = i + r;
}
dijkstra();
printf("%d",second[n-]);
return ;
}
dijkstra
一世安宁
POJ Remmarguts' Date的更多相关文章
- 【POJ】【2449】Remmarguts' Date
K短路/A* 经(luo)典(ti) K短路题目= = K短路学习:http://www.cnblogs.com/Hilda/p/3226692.html 流程: 先把所有边逆向,做一遍dijkstr ...
- poj 2449 Remmarguts' Date(第K短路问题 Dijkstra+A*)
http://poj.org/problem?id=2449 Remmarguts' Date Time Limit: 4000MS Memory Limit: 65536K Total Subm ...
- poj 2449 Remmarguts' Date (k短路模板)
Remmarguts' Date http://poj.org/problem?id=2449 Time Limit: 4000MS Memory Limit: 65536K Total Subm ...
- 图论(A*算法,K短路) :POJ 2449 Remmarguts' Date
Remmarguts' Date Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 25216 Accepted: 6882 ...
- poj 2449 Remmarguts' Date 第k短路 (最短路变形)
Remmarguts' Date Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 33606 Accepted: 9116 ...
- POJ 2449 Remmarguts' Date (第k短路径)
Remmarguts' Date Time Limit: 4000MS Memory Limit: 65536K Total Submissions:35025 Accepted: 9467 ...
- POJ 2449Remmarguts' Date 第K短路
Remmarguts' Date Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 29625 Accepted: 8034 ...
- [poj2449]Remmarguts' Date(spfa+A*)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Remmarguts' Date Time Limit: 4000MS Mem ...
- POJ:2449-Remmarguts' Date(单源第K短路)
Remmarguts' Date Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 33081 Accepted: 8993 Des ...
随机推荐
- SpringCloud+Feign环境下文件上传与form-data同时存在的解决办法(2)
书接上文. 上文中描述了如何在 SpringCloud+Feign环境下上传文件与form-data同时存在的解决办法,实践证明基本可行,但却会引入其他问题. 主要导致的后果是: 1. 无法与普通Fe ...
- linux中crw brw lrw等等文件属性是什么
今天在查看 /dev/fuse 文件的属性的时候,看到了crw_ 权限位,一时反应不过来: [root@localhost ~]# ll /dev/fuse crw-rw-rw-. root root ...
- Fragment分解使用
Fragment碎片:作为Activity的一部分,不能单独使用: 1. Fragment特点: (1)一个Fragment可以在多个Activity中重用: (2)一个Activity内部可以嵌入多 ...
- VS2015 无法启动 IIS Express Web 服务器 解决方案
VS2015 IIS Express 无法启动Web 解决方案 [亲测已成功] 1.我的电脑—管理—事件查看器—Windows日志—应用程序: 详细信息会提示你:[模块 DLL C:\Program ...
- ccf--20151203--画图
本题思路如下: 题目和代码如下: 问题描述 试题编号: 201512-3 试题名称: 画图 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 用 ASCII 字符来画图是一件有趣 ...
- java.sql.SQLSyntaxErrorException: ORA-00904: "column": 标识符无效
java.sql.SQLSyntaxErrorException: ORA-00904: "column": 标识符无效 首先查看无效的列是不是orcale关键字 , 如果不是 , ...
- <项目需求规格说明书> - 福大易宝
福大易宝-<项目需求规格说明书> 流程 在开会时统一了项目的开发背景,具体功能,然后在同一个工作环境下进行该说明书的编写. 分工 1.李佳铭.杜宏庆共同负责引言和项目描述的内容. 2.刘双 ...
- lamp/lnmp下添加PHP扩展
在linux下安装好基本的PHP运行环境后有时候添加了新的功能,就得增加新的扩展,比如之前没有安装redis扩展,可以手动编译安装相关的扩展可以找下下载的php源码包中,ext目录下是否有相关的扩展源 ...
- python六十课——高阶函数之map
1.高阶函数: 特点:函数的形参位置必须接受一个函数对象 分类学习: 1).map(fn,lsd1,[lsd2...]): 参数一:fn --> 函数对象 参数二:lsd1 --> 序列对 ...
- EBS-新增和更新价目表行
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/gh320/article/details/36666133 新增和更新价目表行 --目的:在已 ...