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 ...
随机推荐
- [bash]http serevr部署wordpress
#!/bin/bash # echo "close selinux…" sed -i 's/Enforcing/disabled/' /etc/sysconfig/selinux ...
- 动态规划-LCS-Uncrossed Lines
2020-02-11 21:14:18 问题描述: 问题求解: 本质就是LCS. public int maxUncrossedLines(int[] A, int[] B) { int len1 = ...
- 使用 PyTorch 进行 风格迁移(Neural-Transfer)
1.简介 本教程主要讲解如何实现由 Leon A. Gatys,Alexander S. Ecker和Matthias Bethge提出的Neural-Style 算法.Neural-Style 或者 ...
- coding++:kafka问题:zookeeper is not a recognized option zookeeper参数不支持
– zookeeper is not a recognized option主要原因是 Kafka 版本过高,命令不存在. 使用新版本: ./bin/kafka-console-consumer.sh ...
- n次方
1.问题描述 计算 an 2.算法分析 先将 n 变一变,寻找新的计算路径.预处理就是变治法的根本. 如果单纯循环执行 n 次相乘,那么时间复杂度为 O(n).可以利用二进制幂大大改进效率. 主要思路 ...
- iOS UIViewController的瘦身计划
代码的组织结构,以及为何要这样写. 那些场景适合使用子控制器,那些场景应该避免使用子控制器? 分离UITableView的数据源和UITableViewDataSource协议. MVVM的重点是Vi ...
- 在C#MVC三层项目中如何使用SprintNet
0.添加dll文件 1.首先在根目录下新建一个文件夹[Config],然后新建2两个xml文件. 1-1[controllers.xml]用来配置需要创建的对象 1-2[service.xml]用来配 ...
- [poj1797]Heavy Transportation<最大生成树prim&kruskal>
题目链接:http://poj.org/problem?id=1797 题意:给定n个点,m条边,每条边连接两点切有权值.求点1到点n的路径的上的最小边的值最大... 翻别人博客找到的题,方法挺多的, ...
- JavaScript数组的基本操作
数组的创建方式: 方式一:构造函数构建数组 var arr = new Array ( ); 如果传入的参数为一个数字,代表数组的长度,不包含内容 // 可以传入字符串和数字,用逗号隔开,作为数组中的 ...
- 机器学习——详解KD-Tree原理
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是机器学习的第15篇文章,之前的文章当中讲了Kmeans的相关优化,还讲了大名鼎鼎的EM算法.有些小伙伴表示喜欢看这些硬核的,于是今天上 ...