QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#672668#9488. Do Not Turn BackwallcrackWA 0ms3616kbC++201.4kb2024-10-24 18:02:452024-10-24 18:02:46

Judging History

你现在查看的是最新测评结果

  • [2024-10-24 18:02:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3616kb
  • [2024-10-24 18:02:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int P=998244353;
struct Matrix
{
	int n,m;
	vector<vector<long long>> mat; 
	Matrix(int s1,int s2):
		n(s1),m(s2),mat(n+1,vector<long long>(m+1)){}
	vector<long long>& operator [](int index)
	{
		return mat[index];
	}
	void display()
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
				cout<<mat[i][j]<<" ";
			cout<<endl;
		}
		cout<<"---------------"<<endl;
	}
	void setIdentity()
	{
		for(int i=1;i<=min(n,m);i++)
			mat[i][i]=1;
	}
};
Matrix operator *(Matrix a,Matrix b)
{
	Matrix tmp(a.n,b.m);
	for(int i=1;i<=tmp.n;i++)
		for(int j=1;j<=tmp.m;j++)
		{
			for(int k=1;k<=a.m;k++)
				tmp[i][j]+=a[i][k]*b[k][j]%P;
			tmp[i][j]%=P;
		}
	return tmp;
}
Matrix qpow(Matrix a,int k)
{
	int n=a.n;
	Matrix res(n,n);
	res.setIdentity();
	while(k)
	{
		if(k&1)res=res*a;
		a=a*a;
		k>>=1;
	}
	return res;
}
int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	Matrix trans(2*n,2*n),res(2*n,1);
	for(int i=1;i<=n;i++)
	{
		trans[i+n][i]=1;
		trans[i][i+n]=1;
	}
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		trans[u][v]=trans[v][u]=1;
		trans[u][u+n]--;
		trans[v][v+n]--;
	}
	for(int i=2;i<=n;i++)
		if(trans[1][i])res[n+i][1]=1;
	for(int i=2;i<=n;i++)
		for(int j=2;j<=n;j++)
			if(trans[i][j])res[j][1]+=res[n+i][1];
	res=qpow(trans,k)*res;
	cout<<res[n][1]<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3616kb

input:

6 8 5
1 2
1 3
2 3
2 4
3 5
4 5
4 6
5 6

output:

10

result:

wrong answer 1st words differ - expected: '2', found: '10'