E - Travel by Car
连接https://atcoder.jp/contests/abc143/tasks/abc143_e
题目大意:
在一个无向图中,当前的油量为L,给出q个问题,判断从a到b需要多少加几次油,路上每个节点都可以加油,输出需要加油的最少次数
AC代码:
#include<bits/stdc++.h>
using namespace std;
const int N=;
typedef long long ll;
const ll inf=1e15+;
ll arr[N][N];
ll brr[N][N];
int main(){
ll n,m,l;
cin>>n>>m>>l;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++){
if(i!=j) arr[i][j]=brr[i][j]=inf;
} ll x,y,z; for(int i=;i<=m;i++){
scanf("%lld%lld%lld",&x,&y,&z);
arr[x][y]=z;
arr[y][x]=z;
} for(int k=;k<=n;k++){
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
arr[i][j]=min(arr[i][j],arr[i][k]+arr[k][j]);
} for(int i=;i<=n;i++)
for(int j=;j<=n;j++){
if(arr[i][j]<=l&&i!=j) brr[i][j]=;
} for(int k=;k<=n;k++){
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
brr[i][j]=min(brr[i][j],brr[i][k]+brr[k][j]);
}
int q;
cin>>q;
while(q--){
int a,b;
cin>>a>>b;
if(brr[a][b]>=inf) cout<<-<<endl;
else cout<<brr[a][b]-<<endl;
}
return ;
}
E - Travel by Car的更多相关文章
- 图论 - Travel
Travel The country frog lives in has nn towns which are conveniently numbered by 1,2,…,n. Among n(n− ...
- 【BZOJ-1576】安全路径Travel Dijkstra + 并查集
1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1044 Solved: 363[Sub ...
- Linux inode && Fast Directory Travel Method(undone)
目录 . Linux inode简介 . Fast Directory Travel Method 1. Linux inode简介 0x1: 磁盘分割原理 字节 -> 扇区(sector)(每 ...
- HDU - Travel
Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is t ...
- 2015弱校联盟(1) - I. Travel
I. Travel Time Limit: 3000ms Memory Limit: 65536KB The country frog lives in has n towns which are c ...
- ural 1286. Starship Travel
1286. Starship Travel Time limit: 1.0 secondMemory limit: 64 MB It is well known that a starship equ ...
- Travel Problem[SZU_K28]
DescriptionAfter SzuHope take part in the 36th ACMICPC Asia Chendu Reginal Contest. Then go to QingC ...
- hdu 5441 travel 离线+带权并查集
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Problem Descript ...
- Codeforces Beta Round #51 A. Flea travel 水题
A. Flea travel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem ...
- hdu 5441 Travel 离线带权并查集
Travel Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5441 De ...
随机推荐
- hdu1026Ignatius and the Princess ,又要逃离迷宫了
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1026/ 题意就是一个迷宫,然后有些位置上有守卫,守卫有一个血量,要多花费血量的时间击败他,要求从(0,0)到(n ...
- 灵感来袭,基于Redis的分布式延迟队列
延迟队列 延迟队列,也就是一定时间之后将消息体放入队列,然后消费者才能正常消费.比如1分钟之后发送短信,发送邮件,检测数据状态等. Redisson Delayed Queue 如果你项目中使用了re ...
- [模拟] Codeforces - 1191C - Tokitsukaze and Discard Items
Tokitsukaze and Discard Items time limit per test 1 second memory limit per test 256 megabytes input ...
- iOS提审笔记
查看苹果各大系统的服务状态:中国区服务:https://www.apple.com/cn/support/systemstatus/美国区服务:https://developer.apple.com/ ...
- Ubuntu系统安装wxPython问题
wxPython介绍 wxPython是Python语言的GUI工具包,作为Python的扩展模块实现,包装了wxWidgets.wxPython是跨平台的,开源的.详情 wxPython安装 (1) ...
- 实验十一 MySQLl备份与恢复2
实验十一 MySQL备份与恢复 一. 实验内容: 1. 使用SQL语句导入和导出表数据 2. 使用客户端工具备份还原数据库 3. 使用日志文件恢复数据库 二. 实验项目:学生成绩数据库 创建用于学 ...
- Aho-Corasick automaton
目录 KMP 算法 BF 算法 KMP 算法 避免重复遍历 算法思想 代码实现 匹配函数 求 next 数组 字典树 多模匹配 构造字典树 字典树的结构体定义 构造算法 伪代码 代码实现 失配指针 功 ...
- 在ES5实现ES6中的Object.is方法
ES6中对象的扩展里面添加了一个Object.is方法,用于比较两个值是否严格相等.内部计算与 === 行为基本一致.那么我们怎么在不支持这个方法的ES5中实现呢? 首先我们需要搞清楚两点,1:Obj ...
- HTTP协议的学习总结
HTTP:HyperTextTransferProtocol是一种超文本传输协议,协议用在本地浏览器和服务器之间通信 HTTP基于TCP/IP传输数据,如图片,HTML文件 1.HTTP协议特点: 无 ...
- 自执行函数-[javascript]-[语法]
在看别人的代码的时候,遇到了一种写法,之前没有见过,如下: ![](https://img2018.cnblogs.com/blog/1735896/201912/1735896-2019122114 ...