题目链接->

题解:

次短路模板。

代码:

#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的更多相关文章

  1. 【POJ】【2449】Remmarguts' Date

    K短路/A* 经(luo)典(ti) K短路题目= = K短路学习:http://www.cnblogs.com/Hilda/p/3226692.html 流程: 先把所有边逆向,做一遍dijkstr ...

  2. poj 2449 Remmarguts' Date(第K短路问题 Dijkstra+A*)

    http://poj.org/problem?id=2449 Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Subm ...

  3. poj 2449 Remmarguts' Date (k短路模板)

    Remmarguts' Date http://poj.org/problem?id=2449 Time Limit: 4000MS   Memory Limit: 65536K Total Subm ...

  4. 图论(A*算法,K短路) :POJ 2449 Remmarguts' Date

    Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 25216   Accepted: 6882 ...

  5. poj 2449 Remmarguts' Date 第k短路 (最短路变形)

    Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 33606   Accepted: 9116 ...

  6. POJ 2449 Remmarguts' Date (第k短路径)

    Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Submissions:35025   Accepted: 9467 ...

  7. POJ 2449Remmarguts' Date 第K短路

    Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 29625   Accepted: 8034 ...

  8. [poj2449]Remmarguts' Date(spfa+A*)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Remmarguts' Date Time Limit: 4000MS   Mem ...

  9. POJ:2449-Remmarguts' Date(单源第K短路)

    Remmarguts' Date Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 33081 Accepted: 8993 Des ...

随机推荐

  1. js,H5本地存储

    //存储本地存储----setItem(存储名称,数据名称) var c={name:"man",sex:"woman"}; localStorage.setI ...

  2. 动态切换 web 报表中的统计图类型

    统计图在浏览器端展现时,不同的使用人员对图形的展现形式会有不同的要求,有的需要柱形图.有的想看折线图等,报表支持用户在浏览器端动态的选择统计图类型,关注乾学院,查看具体实现方法动态切换 web 报表中 ...

  3. Kotlin入门(15)独门秘笈之特殊类

    上一篇文章介绍了Kotlin的几种开放性修饰符,以及如何从基类派生出子类,其中提到了被abstract修饰的抽象类.除了与Java共有的抽象类,Kotlin还新增了好几种特殊类,这些特殊类分别适应不同 ...

  4. Django 信息

    Request information USER admin GET No GET data POST No POST data FILES No FILES data COOKIES Variabl ...

  5. beta冲刺随笔集

    团队成员 郑西坤 031602542 (队长) 陈俊杰 031602504 陈顺兴 031602505 张胜男 031602540 廖钰萍 031602323 雷光游 031602319 吴志鸿 03 ...

  6. Derek解读Bytom源码-持久化存储LevelDB

    作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...

  7. linux网关设置

    1.linux中eth0为外网ip.外网网关.外网DNS设置,eth1为内网ip”172.22.0.0/16“不设置网关.DNS. 2.启动linux内核中的IP转发功能 执行vim命令编辑sysct ...

  8. ARC设置

    XCode兼容ARC和非ARC代码的方法 在ARC开发模式下引用非ARC文件或库需进行如下操作以告诉编译器此代码需按照非ARC模式对待: XCode中项目文件->TARGETS->Comp ...

  9. git命令行解决冲突文件步骤

    原文https://blog.csdn.net/zwl18210851801/article/details/79106448 亲测有用,解决git冲突的好办法 方法一(推荐使用): git pull ...

  10. [MySQL学习]STRICT_ALL_TABLES相应的OUT of RANGE VALUE FOR COLUMN和DATA truncated FOR COLUMN

    版权声明:声明:本文档能够转载,须署名原作者. 作者:无为 qq:490073687 周祥兴 zhou.xiangxing210@163.com https://blog.csdn.net/Rooki ...