JZOJ 1267. 路障
1267. 路障(block.pas/c/cpp)
(File IO): input:block.in output:block.out
Description
农村有 R (1 <= R <= 100,000) 条双向的路,每条路连接 N (1 <= N <= 5000) 个结点中的两个。结点的编号是 1..N。Bessie 从结点 1出发,她的朋友(目的地)在结点 N。
次短路径可以使用最短路径上的路,而且允许退回,即到达一个结点超过一次。次短路径是一种长度大于最短路径的路径(如果存在两条或多条最短路径存在,次短路径就是比它们长,且不比其他任何的路径长的路径)。
Input
Lines 2..R+1: 每行包含三个用空格分隔的整数: A, B, 和 D表示有一条路连接结点A和B,长度为D (1 <= D <= 5000)。
Output
Sample Input
4 4
1 2 100
2 4 200
2 3 250
3 4 100
Sample Output
450
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstdlib>
#define N 400007
using namespace std;
int n, m, tot, ans;
struct edge
{
int to, next, w;
}e[N];
int ls[N], f[N], list[N];
int times[N];
bool v[N];
struct A_node
{
int g, h, p;
bool operator < (A_node x) const
{
return x.g + x.h < g + h;
}
};
priority_queue<A_node>Q; void add(int x, int y, int z)
{
e[++tot].to = y;
e[tot].next = ls[x];
e[tot].w = z;
ls[x] = tot;
e[++tot].to = x;
e[tot].next = ls[y];
e[tot].w = z;
ls[y] = tot;
} void spfa()
{
for (int i = ; i <= n; i++)
f[i] = ;
f[n] = ;
int h = , t = ;
list[++t] = n;
v[n] = ;
while (h < t)
{
int p = list[++h];
for (int i = ls[p]; i; i = e[i].next)
if (f[p] + e[i].w < f[e[i].to])
{
f[e[i].to] = f[p] + e[i].w;
if (!v[e[i].to])
{
v[e[i].to] = ;
list[++t] = e[i].to;
}
}
v[p] = ;
}
} int A_star()
{
A_node t1, tmp;
t1.p = , t1.g = , t1.h = ;
Q.push(t1);
while (!Q.empty())
{
t1 = Q.top(); Q.pop();
times[t1.p]++;
if (times[t1.p] == && t1.p == n) return t1.h + t1.g;
if (times[t1.p] > ) continue;
for (int i = ls[t1.p]; i; i = e[i].next)
{
tmp.p = e[i].to;
tmp.g = f[e[i].to];
tmp.h = e[i].w + t1.h;
Q.push(tmp);
}
} } int main()
{
freopen("block.in", "r", stdin);
freopen("block.out", "w", stdout);
scanf("%d%d", &n, &m);
int x, y, z;
for (int i = ; i<= m; i++)
{
scanf("%d%d%d", &x, &y, &z);
add(x, y, z);
}
spfa();
ans = A_star();
printf("%d", ans);
}
JZOJ 1267. 路障的更多相关文章
- 彻底解决phpcms v9升级后,文章发布出现: Mysql 1267错误:MySQL Error : Illegal mix of collations 解决办法
彻底解决phpcms v9升级后,文章发布出现: MySQL Query : SELECT * FROM `withli_a`.`v9_keyword` WHERE `keyword` = '吼吼' ...
- 洛谷 P3395 路障
P3395 路障 题目背景 此题约为NOIP提高组Day1T1难度. 题目描述 B君站在一个n*n的棋盘上.最开始,B君站在(1,1)这个点,他要走到(n,n)这个点. B君每秒可以向上下左右的某个方 ...
- (jzoj snow的追寻)线段树维护树的直径
jzoj snow的追寻 DFS序上搞 合并暴力和,记录最长链和当前最远点,距离跑LCA # include <stdio.h> # include <stdlib.h> # ...
- 并发库应用之八 & 循环路障CyclicBarrier应用
JDK包位置:java.util.concurrent.CyclicBarrier 一个同步辅助类,它允许一组线程互相等待,直到到达某个公共屏障点 (common barrier point).在涉及 ...
- django插入数据库错误:mysql的1267错误
错误信息: django.db.utils.OperationalError: (1267, "Illegal mix of collations (latin1_swedish_ci,IM ...
- [jzoj]3506.【NOIP2013模拟11.4A组】善良的精灵(fairy)(深度优先生成树)
Link https://jzoj.net/senior/#main/show/3506 Description 从前有一个善良的精灵. 一天,一个年轻人B找到她并请他预言他的未来.这个精灵透过他的水 ...
- [jzoj]3468.【NOIP2013模拟联考7】OSU!(osu)
Link https://jzoj.net/senior/#main/show/3468 Description osu 是一款群众喜闻乐见的休闲软件. 我们可以把osu的规则简化与改编成以下的样子: ...
- [jzoj]5478.【NOIP2017提高组正式赛】列队
Link https://jzoj.net/senior/#main/show/5478 Description Sylvia 是一个热爱学习的女孩子. 前段时间,Sylvia 参加了学校 ...
- [jzoj]1115.【HNOI2008】GT考试
Link https://jzoj.net/senior/#main/show/1115 Description 申准备报名参加GT考试,准考证号为n位数X1X2X3...Xn-1Xn(0<=X ...
随机推荐
- Unity Destroy和DestroyImmediate
Destroy(Object obj, float t = 0.0F); 删除一个游戏对象,组件或者资源. 物体obj现在被销毁或在指定了t时间过后销毁.如果obj是组件,它将从GameObject销 ...
- 敏捷开发(Agile development)
敏捷开发(Agile development) 敏捷开发是一种以人为核心.迭代.循序渐进的开发方法.在敏捷开发中,软件项目的构建被切分成多个子项目,各个子项目的成果都经过测试,具备集成和可运行的特征. ...
- Android模拟器使用SD卡
在Android的应用开发中经常要用到与SD卡有关的调试,本文就是介绍关于在Android模拟器中SD卡的使用 一. 准备工作 在介绍之前首先做好准备工作,即配好android的应用开发环境 ...
- Poj 1743——Musical Theme——————【后缀数组,求最长不重叠重复子串长度】
Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22499 Accepted: 7679 De ...
- 北航oo作业第三单元小结
一.梳理JML语言的理论基础 1.jml的注释结构 jml注释语言的每一行都以@作为开始,若是块注释,则需要在注释块的首尾使用/*@ 与@*/ 2.jml的表达式体系 1.原子表达式 表达式可以看作是 ...
- Spring scope 配置
Scope 描述的是 Spring 容器如何新建Bean的实例,Spring的Scope有以下几种,通过@Scope来注解实现: 1. Singleton: 一个Spring容器中只有一个Bean的实 ...
- Web框架的应用
从今天开始,我们将要学习有关Web框架的一些内容,在学习之前先来学习一下http协议,即基于http是如何通信的. http 概要:http是基于tcp/ip通信协议来传输数据的. 优点: 1.简单快 ...
- Excel2Dataset
//获取用户打开的Excel文档路径 private stringkkk() { OpenFileDialog selectFile = new OpenFileDialog(); selectFil ...
- DELL R730安装ESXI虚拟化
dell安装esxi需要dell官方提供的镜像文件地址:http://www.dell.com/support/article/us/en/04/SLN290857/dell%E5%AE%9A%E5% ...
- apply()技巧
apply技巧: 可以将数组的每一项分别作为参数传入函数. var value = [3,6,34,90]; alert(Math.max.apply(Math,value)); 这个技巧的关 ...