Topic: Given a picture, the weight from 1 to reach m must at least traverse how many edges
n<=100, decisive multiplication Floyd
F[TEMP][I][J] Indicates the maximum weight from I to J through the 2^temp Edge.
Update F[temp[i][j]=max{f[temp-1][i][k]+f[temp-1][k][j]}
Then use matrix G[i][j] to record the current weight of the walk, the initial main diagonal is 0, the rest is-∞
From large to small enumeration temp, using f[temp] and g to get matrix H
If the weight in H 1 to a point exceeds m, the current temp is counted in ans and the G array is updated to H
The final output ans+1 is the answer to a slightly
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std;int N;long Long f[70][110][110],g[110][110],h[110][110],m,ans;void Initialize () {Ans=0;memset (f,0xef,sizeof f); memset (g,0xef,sizeof g);} int main () {int t,i,j,k,temp;for (cin>>t; T t--) {Initialize (); Cin>>n>>m;for (i=1;i<=n;i++) for (j=1;j<=n;j++) {#ifndef online_judgescanf ("%I 64d ", &f[0][i][j]); #elsescanf ("%lld ", &f[0][i][j]); #endifif (!f[0][i][j]) f[0][i][j]=0xefefefefefefefefll;} Try{for (temp=1;1ll<<temp<=m;temp++) for (k=1;k<=n;k++) for (i=1;i<=n;i++) for (j=1;j<=n;j++) {f[ Temp][i][j]=max (F[temp][i][j],f[temp-1][i][k]+f[temp-1][k][j]); if (i==1&&f[temp][i][j]>=m) throw (true );}} catch (bool) {}for (i=1;i<=n;i++) g[i][i]=0;while (temp--) {memset (h,0xef,sizeof h); Try{for (k=1;k<=n;k++) for (i= 1;i<=n;i++) for (j=1;j<=n;j++) {H[i][j]=max (h[i][j],f[temp][i][k]+g[k][j]); if (i==1&&h[i][j]>=m) throw (true);} memcpy (g,h,sizeof g); anS+=1ll<<temp;} catch (bool) {}}cout<<ans+1<<endl;} return 0;} LLD!!!!
Bzoj 2165 Building Multiplier Floyd