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 ...
随机推荐
- Hive项目实战:用Hive分析“余额宝”躺着赚大钱背后的逻辑
一.项目背景 前两年,支付宝推出的“余额宝”赚尽无数人的眼球,同时也吸引的大量的小额资金进入.“余额宝”把用户的散钱利息提高到了年化收益率4.0%左右,比起银行活期存储存款0.3%左右高出太多了,也正 ...
- javascript模块化编程规范
一.javascript模块化编程规范: 二.关于commenjs规范和AMD规范: 根本不同:前者用于服务器端同步加载模块:后者是客户端异步加载模块. 同点:两者都有一个全局函数require(), ...
- java字符串与二进制的相互转化
public class StrBinaryTurn { // 将Unicode字符串转换成bool型数组 public boolean[] StrToBool(String input) { boo ...
- 设置VS代码模板
本文URL:http://www.cnblogs.com/CUIT-DX037/p/6770366.html 打开VS安装目录下:\Microsoft Visual Studio 12.0\Commo ...
- 使用SpringSession管理分布式会话时遇到的反序列化问题
关于SpringSession相关的介绍和使用指南,可移步如下网址: [SpringSession管理分布式系统的会话Session] https://www.cnblogs.com/captaina ...
- 【干货】JavaScript DOM编程艺术学习笔记4-6
四.案例研究:JavaScript图片库 js: function showPic(whichpic){ //取得链接 var source=whichpic.getAttribute("h ...
- h5 本地存储
H5本地存储有两个API,一个是Web Storage,还有一个是Web SQL.不管是哪一个,都是基于JavaScript语言来使用,接下来我就教你怎么使用H5本地存储,本文篇幅较大,JS代码较多, ...
- jeesite应用实战(数据增删改查),认真读完后10分钟就能开发一个模块
jeesite配置指南(官方文档有坑,我把坑填了!)这篇文章里,我主要把jeesite官方给出的帮助文档的坑填了,按照里面的方法可以搭建起来jeesite的站点.系统可以运行以后,就可以进入开发模块了 ...
- Openfire+spark在linux上搭建内部聊天系统
一. 实验环境 Ubuntu server14.04 openfire:http://www.igniterealtime.org/downloads/index.jsp spark:http: ...
- java cpu使用率高异常排查
1.top命令对cpu进行排序shift+p 2.pwdx pid查找业务进程路径 3.top -Hp pid查看相关负载线程pid 4.printf “0x%x\n” 线程pid // 将线 ...