标签:链接 int #define .com pen nbsp pre com i++
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1366
#include <iostream> #include <cstdio> #include <set> #define maxn 0x3f3f3f using namespace std; int f[55][55]; char m[55][55]; int main() { // freopen("in.txt","r",stdin); int t; cin>>t; while(t--) { int n,d,ans=0; cin>>n>>d; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i==j) f[i][j]=0; else f[i][j]=maxn; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { cin>>m[i][j]; if(m[i][j]==‘Y‘) f[i][j]=d; } for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { if(f[i][j]>f[i][k]+f[k][j]) f[i][j]=f[i][k]+f[k][j]; } int flag=1; for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) { if(f[i][j]==maxn) { flag=0; break; } else ans=max(f[i][j],ans); } if(flag) cout<<ans<<endl; else cout<<"-1"<<endl; } }
标签:链接 int #define .com pen nbsp pre com i++
原文地址:https://www.cnblogs.com/fantastic123/p/8955672.html