HH去散步
题解
很明显的一道矩阵加速呀!
我们可以将图的连通性用矩阵给表示出来,矩阵的t次方就是跑t秒的结果。
好吧,虽然思路是没问题的但我们很快就发现这样是行不通的,它不能像这样去走,我们又该怎样去处理呢?
之前我们是通过点去建的矩阵,要求不能走回头边,是很难处理的,如果我们用边来建矩阵不就很好处理了吗。
于是我们将边像点一样连起来,只是不把回头的边连着,就可以用矩阵来处理了。
源码
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef long long LL;
const int mo=45989;
struct martix{
int n,m,c[125][125];
martix(){n=m=0;memset(c,0,sizeof(c));}
martix operator * (const mart