2018HDU多校训练-3-Problem M. Walking Plan
Little Q's smart phone will record his walking route. Compared to stay healthy, Little Q cares the statistics more. So he wants to minimize the total walking length of each day. Please write a program to help him find the best route.
, denoting the number of test cases.
In each test case, there are 2
integers n,m(2≤n≤50,1≤m≤10000)
in the first line, denoting the number of intersections and one way streets.
In the next m
lines, each line contains 3
integers ui
,v
i
,w
i
(1≤u
i
,v
i
≤n,u
i
≠v
i
,1≤w
i
≤10000)
, denoting a one way street from the intersection ui
to vi
, and the length of it is wi
.
Then in the next line, there is an integer q(1≤q≤100000)
, denoting the number of days.
In the next q
lines, each line contains 3
integers si
,t
i
,k
i
(1≤s
i
,t
i
≤n,1≤k
i
≤10000)
, describing the walking plan.
3 3
1 2 1
2 3 10
3 1 100
3
1 1 1
1 2 1
1 3 1
2 1
1 2 1
1
2 1 1
1
11
-1
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int N=,M=,maxn=;
int T,n,m,q,u,v,w,s,t,K;
int a[maxn][N][N],b[maxn][N][N],Map[N][N];
int flag[N][N],dis[N][N]; void pre_work(int x[N][N],int y[N][N],int z[N][N])
{
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
flag[i][j]=INF;
for(int k=;k<n;k++)
flag[i][j]=min(flag[i][j],x[i][k]+y[k][j]);
}
}
for(int i=;i<n;i++)
for(int j=;j<n;j++) z[i][j]=flag[i][j];
} int main()
{
ios::sync_with_stdio(false);
cin.tie();
cin>>T;
while(T--)
{
cin>>n>>m;
for(int i=;i<n;i++)
{
for(int j=;j<n;j++) Map[i][j]=INF;
}
while(m--)
{
cin>>u>>v>>w;
Map[u-][v-]=min(Map[u-][v-],w);
} for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
a[][i][j]=b[][i][j]= i==j? :INF;
}
for(int i=;i<M;i++) pre_work(a[i-],Map,a[i]);//处理出经过i步从 x->y 的最短路
for(int i=;i<M;i++) pre_work(b[i-],a[],b[i]);//处理出从 x->y 恰好走 100*i步 //Floyd
for(int i=;i<n;i++)
{
for(int j=;j<n;j++) dis[i][j]= i==j? :Map[i][j];
}
for(int k=;k<n;k++)
{
for(int i=;i<n;i++)
{
for(int j=;j<n;j++) dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}
} for(int x=;x<M;x++)
{
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
flag[i][j]=INF;
for(int k=;k<n;k++) flag[i][j]=min(flag[i][j],b[x][i][k]+dis[k][j]);
}
}
for(int i=;i<n;i++) for(int j=;j<n;j++) b[x][i][j]=flag[i][j];
} cin>>q;
while(q--)
{
cin>>s>>t>>K; s--,t--;
int r=K/,l=K%,ans=INF;
for(int i=;i<n;i++) ans=min(ans,b[r][s][i]+a[l][i][t]);
if(ans>=INF) cout<<-<<endl;
else cout<<ans<<endl;
}
} return ;
}
2018HDU多校训练-3-Problem M. Walking Plan的更多相关文章
- HDU6331 Problem M. Walking Plan【Floyd + 矩阵 + 分块】
HDU6331 Problem M. Walking Plan 题意: 给出一张有\(N\)个点的有向图,有\(q\)次询问,每次询问从\(s\)到\(t\)且最少走\(k\)条边的最短路径是多少 \ ...
- 2018HDU多校训练-3-Problem G. Interstellar Travel
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6325 Interstellar Tra ...
- 2018HDU多校训练-3-Problem D. Euler Function
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6322 Problem Description In number theory, Euler's toti ...
- 2018HDU多校训练一 K - Time Zone
Chiaki often participates in international competitive programming contests. The time zone becomes a ...
- 2018HDU多校训练-3-Problem F. Grab The Tree
Little Q and Little T are playing a game on a tree. There are n vertices on the tree, labeled by 1,2 ...
- 2018HDU多校训练一 D Distinct Values
hiaki has an array of nn positive integers. You are told some facts about the array: for every two e ...
- 2018HDU多校训练一 C -Triangle Partition
Chiaki has 3n3n points p1,p2,-,p3np1,p2,-,p3n. It is guaranteed that no three points are collinear. ...
- 2018HDU多校训练一 A - Maximum Multiple
Given an integer nn, Chiaki would like to find three positive integers xx, yy and zzsuch that: n=x+y ...
- hdu6331 Problem M. Walking Plan
传送门 题目大意 给你一个n点m条边的有向图,q次询问,给定s,t,k,求由s到t至少经过k条边的最短路. 分析 我们设dp[i][j][k]为从i到j至少经过k条边的最短路,sp[i][j]意为从i ...
随机推荐
- java编程思想第四版第十章习题
第一题 package net.mindview.innerclasses; public class Outer { class Inner { Inner(){ System.out.printl ...
- pat 1058 A+B in Hogwarts(20 分)
1058 A+B in Hogwarts(20 分) If you are a fan of Harry Potter, you would know the world of magic has i ...
- hdu 1269 迷宫城堡 (tarjan)
迷宫城堡Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- NetCore3.0 文件上传与大文件上传的限制
NetCore文件上传两种方式 NetCore官方给出的两种文件上传方式分别为“缓冲”.“流式”.我简单的说说两种的区别, 1.缓冲:通过模型绑定先把整个文件保存到内存,然后我们通过IFormFile ...
- Java内存模型与volatile关键字
Java内存模型与volatile关键字 一).并发程序开发 并行程序的开发要涉及多线程.多任务间的协作和数据共享问题. 常用的并发控制:内部锁.重入锁.读写锁.信号量. 二).线程的特点 线程的特点 ...
- 20191031-9 beta week 1/2 Scrum立会报告+燃尽图 07
此作业要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/9917 一.小组情况 队名:扛把子 组长:孙晓宇 组员:宋晓丽 梁梦瑶 韩昊 ...
- 20191017-3 alpha week 2/2 Scrum立会报告+燃尽图 02
此作业要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/9799 一.小组情况 队名:扛把子 组长:迟俊文 组员:宋晓丽 梁梦瑶 韩昊 ...
- 正则表达式 第六篇:调用CLR函数执行正则查询
在SQL Server数据库中可以执行模糊查询,像like子句,和全文查询(Fulltext search),但是无法直接执行正则查找,SQL Server没有执行正则表达式的内置函数,但是我们可以创 ...
- 2019-10-23:渗透测试,基础学习,DVWA,Medium和Hight级别sql注入
VWA的Medium和Hight级别sql注入 一,Medium级 服务端代码 <?php if( isset( $_POST[ 'Submit' ] ) ) { // Get inp ...
- 关于vue中的videoPlayer的src视频地址参数动态修改(网上一堆错误方法,被误导很久,自己找到了正确的方法,供大家借鉴)
方法很简单:相信大家的问题应该是改变src的值吧,动态赋值这一步简单.this.playerOptions['sources'][0]['src'] 就是这一步解决提取src问题,主要部分用绿色框起来 ...