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. GIT主要用到的命令

    git add . //添加到暂存盘 git commit -m ‘备注’//提交到本地仓库 git push //提交到远程仓库 fetch更新本地仓库两种方式: //方法一 $ git fetch ...

  2. 解决Linux下SSH等终端乱码问题

    1.vi /etc/sysconfig/i18n Centos5.5原来内容是: //LANG="en_US.UTF-8" //SYSFONT="latarcyrheb- ...

  3. cas 单点登录服务端客户端配置

    首先,下载 cas-server-3.5.2-release http://pan.baidu.com/s/1GJ8Gs cas-client-3.2.1-release http://pan.bai ...

  4. Uncaught Error: Bootstrap's JavaScript requires jQuery

    在写bootstarp的时候,一直报 Uncaught Error: Bootstrap's JavaScript requires jQuery 查看了自己引入的文件路径是对的,也可以使用jquer ...

  5. 拖拽调整Div大小

    今天写了一天这个jquery插件: 可以实现对div进行拖拽来调整大小的功能. (function ($) { $.fn.dragDivResize = function () { var delta ...

  6. (转载)23种设计模式的uml图表示及通俗介绍

    转载自: https://www.cnblogs.com/ningskyer/articles/3615312.html 0.分类 创建型模式 1.FACTORY2.BUILDER3.FACTORY ...

  7. 好吧,不说闲言碎语,不抱怨,好好工作,好好学习,多总结。记录一下昨天做vuejs的心得

    1.做了两个bat文件,一个是直接定位到vuejs项目并且运行,另一个就是打包 run.bat d:cd wwwcd vuecd dtbpmcnpm run devpause build.bat cd ...

  8. ABAP跳转屏幕

    1.call transaction语句跳转屏幕 '. CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN. . 2.调用函数 CALL FUNCTION 'M ...

  9. ubuntu server 16.04安装GPU服务器

    1 Ubuntu16.04 系统安装过程中,需要勾选openssh-server 方便远程连接 2 必须安装gcc 与g++ 3 安装显卡驱动 NVIDIA-Linux-x86_64-367.57.r ...

  10. 一键部署joomla开源内容管理平台

    https://market.azure.cn/Vhd/Show?vhdId=10896&version=12949 产品详情 产品介绍Joomla是一套自由.开放源代码的内容管理系统,以PH ...