bzoj4956: [Wf2017]Secret Chamber at Mount Rushmore
F......loyd?
这范围也是.....
然而大了也不会....
#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> using namespace std; int mp[30][30]; char s1[60],s2[60]; int main() { int n,m; scanf("%d%d",&m,&n); memset(mp,63,sizeof(mp)); for(int i=1;i<=26;i++)mp[i][i]=1; for(int i=1;i<=m;i++) { scanf("%s%s",s1+1,s2+1); mp[s1[1]-'a'+1][s2[1]-'a'+1]=1; } for(int k=1;k<=26;k++) for(int i=1;i<=26;i++) if(k!=i) for(int j=1;j<=26;j++) if(i!=j&&k!=j) mp[i][j]=min(mp[i][j],mp[i][k]+mp[k][j]); while(n--) { scanf("%s%s",s1+1,s2+1); int len1=strlen(s1+1),len2=strlen(s2+1); if(len1!=len2){printf("no\n");continue;} bool bk=false; for(int i=1;i<=len1;i++) if(mp[s1[i]-'a'+1][s2[i]-'a'+1]>999999999){bk=true;break;} if(bk==false)printf("yes\n"); else printf("no\n"); } return 0; }
pain and happy in the cruel world.