有生以来做过的bzoj比A+B还简单的最水的题。(确信)
不解释。
UPD:据说这题正解应当是矩阵树定理?但是这个不是用来最小生成树计数的么?有生之年会补的。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define dbg(x) cerr << #x << " = " << x <<endl
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
template<typename T>inline T _min(T A,T B){return A<B?A:B;}
template<typename T>inline T _max(T A,T B){return A>B?A:B;}
template<typename T>inline char MIN(T&A,T B){return A>B?(A=B,):;}
template<typename T>inline char MAX(T&A,T B){return A<B?(A=B,):;}
template<typename T>inline void _swap(T&A,T&B){A^=B^=A^=B;}
template<typename T>inline T read(T&x){
x=;int f=;char c;while(!isdigit(c=getchar()))if(c=='-')f=;
while(isdigit(c))x=x*+(c&),c=getchar();return f?x=-x:x;
}
const int N=,P=1e9+;
char s[N];
int n;
struct thxorz{int to,nxt,w;}G[];
int Head[N],tot;
inline void Addedge(int x,int y,int z){G[++tot].to=y,G[tot].nxt=Head[x],Head[x]=tot,G[tot].w=z;}
#define y G[j].to
int dis[N],cnt[N];
priority_queue<pii,vector<pii>,greater<pii> > q;
inline void stothxorz(){
memset(dis,0x3f,sizeof dis);q.push(make_pair(dis[]=,));cnt[]=;
while(!q.empty()){
int x=q.top().second,d=q.top().first;q.pop();
if(dis[x]^d)continue;
for(register int j=Head[x];j;j=G[j].nxt)
if(dis[y]==d+G[j].w)++cnt[y];
else if(MIN(dis[y],d+G[j].w))cnt[y]=,q.push(make_pair(dis[y],y));
}
}
#undef y
int main(){//freopen("test.in","r",stdin);//freopen("test.ans","w",stdout);
read(n);
for(register int i=;i<=n;++i){
scanf("%s",s+);
for(register int j=;j<=n;++j)if(s[j]-'')Addedge(i,j,s[j]-'');
}
stothxorz();
int res=;
for(register int i=;i<=n;++i)res=res*1ll*cnt[i]%P;
printf("%d\n",res);
return ;
}