矩阵树定理,注意gauss消元辗转相除的写法
#include<bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma
#define
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define
ll a[MAXN][MAXN];
ll det(int n) {
bool f=0;
For(i,n) {
int k=i;
Fork(j,i,n) if (abs(a[j][i])>abs(a[k][i])) {k=j;break;}
For(j,n) swap(a[i][j],a[k][j]);
if (i^k) f^=1;
Fork(j,i+1,n) {
while(a[j][i]) {
ll t=a[j][i]/a[i][i];
For(k,n) {
a[j][k]+=F-t*a[i][k]%F;
a[j][k]%=F;
}
if (!a[j][i]) break;
f^=1;
For(k,n) swap(a[j][k],a[i][k]);
}
}
}
ll r=1;
For(i,n) r=r*a[i][i]%F;
if (f) r=F-r;
return r%F;
}
int id[MAXN][MAXN],cnt=0;
int main()
{
// freopen("bzoj4031.in","r",stdin);
// freopen(".out","w",stdout);
int n=read(),m=read();
char s[MAXN][MAXN];
int cnt=0;
For(i,n) {
scanf("%s",s[i]+1);
For(j,m) if (s[i][j]=='.') id[i][j]=++cnt;
}
For(i,n) For(j,m) if (s[i][j]=='.'){
if (i>1) {
int x=i,y=j,nx=i-1,ny=j;
if (s[nx][ny]=='.') {
int u=id[x][y],v=id[nx][ny];
a[u][v]--; a[v][u]--;
a[u][u]++; a[v][v]++;
}
}
if (j>1) {
int x=i,y=j,nx=i,ny=j-1;
if (s[nx][ny]=='.') {
int u=id[x][y],v=id[nx][ny];
a[u][v]--; a[v][u]--;
a[u][u]++; a[v][v]++;
}
}
}
printf("%lld\n",det(cnt-1));
return 0;
}