提交时间:2024-10-04 21:13:07
运行 ID: 33304
#include<bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define fr first #define sc second #define mk make_pair int read(){int x=0,f=1;char c=getchar();while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;} const int MAXN=100010,N=80,Mod=1000000007,B=300; int Pow(int x,int y){int rt=1;while(y){if(y&1)rt=rt*x%Mod;x=x*x%Mod,y>>=1;}return rt;} int n,m,k,d[MAXN],ans; char c[N][N]; struct matrix{ int p[N][N],x,y; matrix operator*(const matrix&G)const{ matrix res;res.x=x,res.y=G.y; for(int i=1;i<=x;i++){ for(int j=1;j<=G.y;j++){ res.p[i][j]=0; for(int o=1;o<=y;o++){ res.p[i][j]=(res.p[i][j]+p[i][o]*G.p[o][j]%Mod)%Mod; } } } return res; } void prt(){ for(int i=1;i<=x;i++){ for(int j=1;j<=y;j++)cout<<p[i][j]<<" "; cout<<endl; } } }P,F,M[B+10]; pii a[MAXN]; void slv(){ n=read(),m=read(),k=read(); for(int i=1;i<=n;i++)scanf("%s",c[i]+1); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(c[i][j]=='1')d[i]++; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(c[i][j]=='1')P.p[i][j]=Pow(d[i],Mod-2); P.x=P.y=n; M[1]=P; for(int i=2;i<=B;i++){ M[i]=M[i-1]*P; } F.x=1,F.y=n; for(int i=1;i<=m;i++){ a[i].fr=read(),a[i].sc=read(); } sort(a+1,a+m+1); a[m+1].fr=k+1; for(int i=1,j=1;j<=m;){ while(j<=m&&a[j].fr==i)F.p[1][a[j].sc]++,F.p[1][a[j].sc]%=Mod,j++; // cout<<i<<":"<<endl; // F.prt(); while(a[j].fr-i>=B){ ans^=F.p[1][n]; // cout<<i<<":"<<F.p[1][n]<<endl; for(int o=i+1;o<i+B;o++){ int tmp=0; for(int x=1;x<=n;x++){ tmp+=(F.p[1][x]*M[o-i].p[x][n])%Mod; tmp%=Mod; } ans^=tmp; // cout<<o<<":"<<tmp<<endl; } F=F*M[B]; i+=B; } // cout<<i<<":"<<endl; // F.prt(); if(i<a[j].fr){ ans^=F.p[1][n]; // cout<<i<<":"<<F.p[1][n]<<endl; for(int o=i+1;o<a[j].fr;o++){ int tmp=0; for(int x=1;x<=n;x++){ tmp+=(F.p[1][x]*M[o-i].p[x][n])%Mod; tmp%=Mod; } ans^=tmp; // cout<<o<<":"<<tmp<<endl; } F=F*M[a[j].fr-i]; i+=a[j].fr-i; } // cout<<i<<":"<<endl; // F.prt(); } printf("%lld",ans); } signed main(){ slv(); return 0; }