Firdaws and Fatinah are living in a country with nn cities, numbered from 11 to nn.Each city has a risk of kidnapping or robbery.

Firdaws's home locates in the city uu, and Fatinah's home locates in the city vv.Now you are asked to find the shortest path from the city uu to the city vv that does not pass through any other city with the risk of kidnapping or robbery higher than ww, a threshold given by Firdaws.

Input Format

The input contains several test cases, and the first line is a positive integer TT indicating the number of test cases which is up to 5050.

For each test case, the first line contains two integers n~(1\le n\le 200)n (1≤n≤200) which is the number of cities, and q~(1\le q\le 2\times 10^4)q (1≤q≤2×104) which is the number of queries that will be given.The second line contains nn integers r_1, r_2, \cdots, r_nr1​,r2​,⋯,rn​ indicating the risk of kidnapping or robbery in the city 11 to nn respectively.Each of the following nnlines contains nn integers, the jj-th one in the ii-th line of which, denoted by d_{i,j}di,j​, is the distance from the city ii to the city jj.

Each of the following qq lines gives an independent query with three integers u, vu,v and ww, which are described as above.

We guarantee that 1\le r_i \le 10^51≤ri​≤105, 1\le d_{i,j}\le 10^5~(i \neq j)1≤di,j​≤105 (i≠j), d_{i,i}=0di,i​=0 and d_{i,j}=d_{j,i}di,j​=dj,i​.Besides, each query satisfies 1\le u,v\le n1≤u,v≤n and 1\le w\le 10^51≤w≤105.

Output Format

For each test case, output a line containing Case #x: at first, where xx is the test case number starting from 11.Each of the following qq lines contains an integer indicating the length of the shortest path of the corresponding query.

样例输入

1
3 6
1 2 3
0 1 3
1 0 1
3 1 0
1 1 1
1 2 1
1 3 1
1 1 2
1 2 2
1 3 2

样例输出

Case #1:
0
1
3
0
1
2

题目来源

The 2018 ACM-ICPC Chinese Collegiate Programming Contest

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
typedef long long ll;
#define lowbit(x) (x&(-x))
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
using namespace std;
#define pi acos(-1)
const int N=;
const int inf=0x3f3f3f3f;
int r[N],f[N][N][N];
int t,n,q;
int id[N];
void solve(int n){
for(int k=;k<=n;k++){
int kk=id[k];//实际顺序
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
f[k][i][j]=min(f[k-][i][j],f[k-][i][kk]+f[k-][kk][j]);
}
}
}
}
bool cmp(int i,int j){
return r[i]<r[j];
}
int main()
{
scanf("%d",&t);
int i;
for(i=;i<=t;i++){
scanf("%d%d",&n,&q);
for(int j=;j<=n;j++){
id[j]=j;
scanf("%d",&r[j]);
}
memset(f,inf,sizeof(f));
for(int k1=;k1<=n;k1++){
for(int k2=;k2<=n;k2++){
scanf("%d",&f[][k1][k2]);
}
}
sort(id+,id+n+,cmp);//按照r[]从小到大排序,为了solve()
sort(r+,r+n+);//为了找符合条件的k4
solve(n);
printf("Case #%d:\n",i);
int u,v,w;
for(int k3=;k3<=q;k3++){
scanf("%d%d%d",&u,&v,&w);
int k4;
for(k4=;k4<=n;k4++){
if(r[k4]>w){
break;
}
}
printf("%d\n",f[k4-][u][v]);
}
}
return ;
}

The 2018 ACM-ICPC Chinese Collegiate Programming Contest Moving On的更多相关文章

  1. ACM ICPC, JUST Collegiate Programming Contest (2018) Solution

    A:Zero Array 题意:两种操作, 1 p v  将第p个位置的值改成v  2  查询最少的操作数使得所有数都变为0  操作为可以从原序列中选一个非0的数使得所有非0的数减去它,并且所有数不能 ...

  2. ACM ICPC, Amman Collegiate Programming Contest (2018) Solution

    Solution A:Careful Thief 题意:给出n个区间,每个区间的每个位置的权值都是v,然后找长度为k的区间,使得这个区间的所有位置的权值加起来最大,输出最大权值, 所有区间不重叠 思路 ...

  3. ICPC — International Collegiate Programming Contest Asia Regional Contest, Yokohama, 2018–12–09 题解

    目录 注意!!此题解存在大量假算法,请各位巨佬明辨! Problem A Digits Are Not Just Characters 题面 题意 思路 代码 Problem B Arithmetic ...

  4. 计蒜客 The 2018 ACM-ICPC Chinese Collegiate Programming Contest Rolling The Polygon

    include <iostream> #include <cstdio> #include <cstring> #include <string> #i ...

  5. The 2018 ACM-ICPC Chinese Collegiate Programming Contest Take Your Seat

    /* 证明过程如下 :第一种情况:按1到n的顺序上飞机,1会随意选一个,剩下的上去时若与自己序号相同的座位空就坐下去,若被占了就也会随意选一个.求最后一个人坐在应坐位置的概率 */ #include ...

  6. The 2018 ACM-ICPC Chinese Collegiate Programming Contest Fight Against Monsters

    #include <iostream> #include <cstdio> #include <cstring> #include <string> # ...

  7. The 2018 ACM-ICPC Chinese Collegiate Programming Contest Caesar Cipher

    #include <iostream> #include <cstdio> #include <cstring> #include <string> # ...

  8. The 2018 ACM-ICPC Chinese Collegiate Programming Contest Maximum Element In A Stack

    //利用二维数组模拟 #include <iostream> #include <cstdio> #include <cstring> #include <s ...

  9. ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018

    ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syr ...

随机推荐

  1. java exception "file not found or file not exist"

    出现这种异常一般有两种原因,第一种就是文件真的不存在:第二种是权限问题,权限问题又分为文件本身的权限和包含它的文件夹的权限 比如 ~/aaa/bbb/ccc/ddd/eee.txt  只要 aaa , ...

  2. 软件模拟I2C时输入与输出切换

    一 为达到类似C51的操作需要添加以下位带操作:#include "stm32f10x_gpio.h"#include "stm32f10x_conf.h" / ...

  3. POJ 3735 Training little cats 矩阵快速幂

    http://poj.org/problem?id=3735 给定一串操作,要这个操作连续执行m次后,最后剩下的值. 记矩阵T为一次操作后的值,那么T^m就是执行m次的值了.(其实这个还不太理解,但是 ...

  4. 牛客网Java刷题知识点之抽象类与接口

    不多说,直接上干货! 接口和内部类为我们提供了一种将接口与实现分离的更加结构化的方法. 抽象类与接口是Java语言中对抽象概念进行定义的两种机制,正是由于它们的存在才赋予java强大的面向对象的能力. ...

  5. C#实现程序单例日志输出

    对于一个完整的程序系统,一个日志记录是必不可少的.可以用它来记录程序在运行过程中的运行状态和报错信息.比如,那些不想通过弹框提示的错误,程序执行过程中捕获的异常等. 首先,在你的解决方案中,适当的目录 ...

  6. c# 字符串的首字母大写转换 方法

    方法1: s.Substring(0,1).ToUpper()+s.Substring(1);  方法2: s = System.Threading.Thread.CurrentThread.Curr ...

  7. Java面向对象(类、封装)

    面向对象 今日内容介绍 u 面向对象 u 封装 第1章 面向对象 1.1 理解什么是面向过程.面向对象 面向过程与面向对象都是我们编程中,编写程序的一种思维方式. l 面向过程的程序设计方式,是遇到一 ...

  8. dubbo服务降级(2)

    dubbo降级服务 使用dubbo在进行服务调用时,可能由于各种原因(服务器宕机/网络超时/并发数太高等),调用中就会出现RpcException,调用失败. 服务降级就是指在由于非业务异常导致的服务 ...

  9. 【Unity3D】射箭打靶游戏(简单工厂+物理引擎编程)

    打靶游戏:     1.靶对象为 5 环,按环计分:    2.箭对象,射中后要插在靶上:    3.游戏仅一轮,无限 trials: 增强要求:  添加一个风向和强度标志,提高难度 游戏成品图: U ...

  10. 【selenium学习笔记一】python + selenium定位页面元素的办法。

    1.什么是Selenium,为什么web测试,大家都用它? Selenium设计初衷就是为web项目的验收测试再开发.内核使用的是javaScript语言编写,几乎支持所以能运行javaScript的 ...