## The 2019 Asia Yinchuan First Round Online Programming F. Moving On

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
using namespace std;

typedef long long LL;
#define inf 1e9
#define rep(i, j, k) for (int i = (j); i <= (k); i++)
#define rep__(i, j, k) for (int i = (j); i < (k); i++)
#define per(i, j, k) for (int i = (j); i >= (k); i--)
#define per__(i, j, k) for (int i = (j); i > (k); i--)

const int N = 210;
int f[N][N][N];
int n,q;
int u,v,w;

struct node{
int id;
int ATK;

friend bool operator<(const node& a,const node& b){
return a.ATK < b.ATK;
}
}W[N];

int main(){

int T;
scanf("%d",&T);

rep(o,1,T){
scanf("%d%d",&n,&q);

rep(i,1,n){
W[i].id = i;
scanf("%d",&W[i].ATK);
}

sort(W + 1,W + n + 1);

rep(i,1,n) rep(j,1,n){
if(i == j) f[0][i][j] = 0;
else f[0][i][j] = inf;
}

rep(i,1,n) rep(j,1,n){
scanf("%d",&w);
f[0][i][j] = w;
}

// rep(i,1,n) cout << W[i].ATK << endl;

// rep(i,1,n){
//     rep(j,1,n) cout << f[0][i][j] << " ";
//     cout << endl;
// }

rep(k,1,n) rep(i,1,n) rep(j,1,n){
f[k][i][j] = min(f[k-1][i][j],f[k-1][i][W[k].id]+f[k-1][W[k].id][j]);
}

printf("Case #%d:\n",o);

int tmp;
rep(i,1,q){
scanf("%d%d%d",&u,&v,&w);
tmp = 0;
rep(j,1,n) if(W[j].ATK <= w) tmp = j;
printf("%d\n",f[tmp][u][v]);
}
}

getchar();getchar();
return 0;
}

posted on 2019-09-05 17:35  SSummerZzz  阅读(...)  评论(...编辑  收藏

• 随笔 - 85
• 文章 - 0
• 评论 - 2
• 引用 - 0