QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658595 | #9488. Do Not Turn Back | ucup-team5318# | RE | 0ms | 0kb | C++14 | 1.0kb | 2024-10-19 17:06:59 | 2024-10-19 17:07:01 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=205,mod=998244353;
int n,m,k,d[N];
vector<int>e[N];
struct Mat{
ll a[N][N];
Mat(int p=0){memset(a,0,sizeof(a));if(p)for(int i=1;i<=n*2;i++)a[i][i]=1;}
friend Mat operator*(const Mat&x,const Mat&y) {
Mat z;
for(int i=1;i<=n*2;i++)for(int j=1;j<=n*2;j++)for(int k=1;k<=n*2;k++)
z.a[i][j]=(z.a[i][j]+x.a[i][k]*y.a[k][j])%mod;
return z;
}
};
Mat qp(Mat a,int b){Mat ans(1);for(;b;b>>=1,a=a*a)if(b&1)ans=ans*a;return ans;}
int main() {
freopen(".in","r",stdin);
freopen(".out","w",stdout);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>m>>k;
for(int i=1,x,y;i<=m;i++)cin>>x>>y,e[x].push_back(y),e[y].push_back(x),d[x]++,d[y]++;
Mat st,F;
for(int i=1;i<=n;i++) {
for(int j:e[i])st.a[i][j]=1;
st.a[i][i+n]=1,st.a[i+n][i]=-d[i];
}
if(k<=2) {
F=qp(st,k);
}else {
F=qp(st,2);
for(int i=1;i<=n;i++)st.a[i+n][i]++;
F=F*qp(st,k-2);
}
cout<<(F.a[1][n]+mod)%mod<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
6 8 5 1 2 1 3 2 3 2 4 3 5 4 5 4 6 5 6