令:
d[k][i][j]表示i到j 刚好经过k条边,的最短路。
显然 输出数据是k=1的情况。
对于dp[k][i][j]转移有:
dp[k][i][j]=min(dp[a][i][l]+dp[b][l][j]); // 1<=l<=sz,a+b==k.即:恰好经过a条边的状态和恰好经过b条边的状态,合并即恰好经过
a+b条边的状态。
发现:这很想矩阵转移。
满足结合律。即可以先执行某一对的矩阵转移(顺序不能改变)
所以用矩阵快速幂加速转移即可。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 2e2+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,0,sizeof(head));}
struct EDGE{int to,nxt,val;}ee[M*2];
void add(int x,int y){ee[++cnt].nxt=head[x],ee[cnt].to=y,head[x]=cnt;}
*/
ll li[M],sz;
struct node{
ll a[110][110];
}d;
node operator *(node a,node b)
{
node c;
memset(c.a,0x3f,sizeof(c.a));
for(int i=1;i<=sz