F. Moving On

http://codeforces.com/gym/102222/problem/F

fory 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lson root<<1,l,midd
#define rson root<<<1|1,midd+1,r
#define pb push_back
const int M=220;
const int inf=0x3f3f3f3f;
int a[M],b[M],dp[M][M][M];
bool cmp(int x,int y){
    return a[x]<a[y];
}
int main(){
    int t;
    scanf("%d",&t);
    for(int l=1;l<=t;l++){
        int n,m;
        scanf("%d%d",&n,&m);
        memset(dp,inf,sizeof(dp));
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]),b[i]=i;
        sort(b+1,b+1+n,cmp);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                scanf("%d",&dp[0][i][j]);
        for(int k=1;k<=n;k++){
            int now=b[k];
            for(int i=1;i<=n;i++)
                for(int j=1;j<=n;j++)
                    dp[k][i][j]=min(dp[k-1][i][j],dp[k-1][i][now]+dp[k-1][now][j]);
        }
        printf("Case #%d:\n",l);
        while(m--){
            int u,v,up;
            scanf("%d%d%d",&u,&v,&up);
            int mubiao=0;
            for(int i=1;i<=n;i++){
                if(a[b[i]]>up)
                    break;
                mubiao++;
            }
            printf("%d\n",dp[mubiao][u][v]);
        }
    }
    return 0;
}
View Code

 

posted @ 2019-08-31 15:05  starve_to_death  阅读(251)  评论(0编辑  收藏  举报