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. [HNOI 2012]三角形覆盖问题

    Description 二维平面中,给定   N个等腰直角三角形(每个三角形的两条直角边分别     平行于坐标轴,斜边从左上到右下).我们用三个非负整数( x, y, d)来描   述这样一个三角形 ...

  2. c# 类名不同,字段相同,如何快速给类赋值

    1,相关的两个类如下:现在我们知道短信的值,如何给微信来赋值呢,需要用到我们的反射,当然字段一一赋值也可以,但是如果字段有100个,这个方法就不行啦 /// <summary> /// 短 ...

  3. HashMap与TreeMap

    package com.jckb; import java.util.Map; import java.util.Set; import java.util.TreeMap; /**TreeMap * ...

  4. 【复习笔记】CSS基础

    外观 color:rgba(255,255,255,1),a表示alpha,透明度值0~1 font-family:字体1,字体2,字体3;确保某字体不存在时自动选择下一个,最好使用字体的英文名称保证 ...

  5. 中国各运营商(电信、联通、移动、铁通)IP地址段

    除此电信.联通.移动.铁通之外还有教育网.科技网.广电.长城.广电…… 表格下载: http://files.cnblogs.com/files/xiaohi/中国IP网段.zip 以上资料参考: h ...

  6. 如何用JavaScript实现2+2=5?

    我大学毕业找工作时,经常做一些稀奇古怪的面试题.这不,给大家分享一道整蛊的面试题,它其实不能算一道正式的面试题,大家可以用它来捉弄你们那些程序员朋友. 题目:如何用JavaScript实现2+2=5? ...

  7. SpringMVC归纳

    SpringMVC归纳 操作流程 配置前端控制器 在web.xml中配置 配置处理器映射器 在springmvc配置文件中配置 配置处理器适配器 在springmvc配置文件中配置 配置注解适配器和映 ...

  8. Beta冲刺(周四)

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1 这个作业要求在哪里 https://edu.cnblo ...

  9. 使用EventLog组件向本机现有日志中添加条目

    实现效果: 知识运用: EventLog组件的MachineName属性 //获取或设置在其上读取或写入事件的计算机名称 public string MachineName  {get;set; } ...

  10. C++ Stack 与String

    // ConsoleApplication1.cpp : 此文件包含 "main" 函数.程序执行将在此处开始并结束. // #include "pch.h" ...