QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#656091#9488. Do Not Turn Backucup-team4938#TL 573ms8972kbC++142.7kb2024-10-19 11:18:082024-10-19 11:18:09

Judging History

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

  • [2024-10-19 11:18:09]
  • 评测
  • 测评结果:TL
  • 用时:573ms
  • 内存:8972kb
  • [2024-10-19 11:18:08]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=110;
const int inf=1e18;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n,m,k;
int head[maxn],tot;
struct nd{
	int nxt,to;
}e[maxn*maxn<<1];
void add(int u,int v){e[++tot]={head[u],v};head[u]=tot;}
int d[maxn];
int dp[maxn][maxn];
struct mat{
	int e[maxn*3][maxn*3];
	mat(){mems(e,0);}
	mat operator*(const mat&tmp)const{
		mat res;
		for(int i=0;i<=m;i++){
			for(int j=0;j<=m;j++){
				for(int k=0;k<=m;k++)(res.e[i][j]+=e[i][k]*tmp.e[k][j])%=mod;
			}
		}
		return res;
	}
}a,b;
mat one(){
	mat res;
	for(int i=0;i<=m;i++)res.e[i][i]=1;
	return res;
}
mat ksm(mat a,int b){
	mat ans=one();
	while(b){
		if(b&1)ans=ans*a;
		a=a*a;
		b>>=1;
	}
	return ans;
}
int id(int u,int v){return u*n+v;}
void work(){
	n=read();m=read();k=read();
	for(int i=1;i<=m;i++){
		int u=read(),v=read();
		add(u,v),add(v,u),d[u]++,d[v]++;
	}
	// for(int i=1;i<=n;i++)cout<<d[i]<<" ";cout<<"\n";
	dp[0][1]=1;
	for(int i=1;i<=5;i++){
		for(int u=1;u<=n;u++){
			for(int ii=head[u];ii;ii=e[ii].nxt){
				int v=e[ii].to;
				(dp[i][v]+=dp[i-1][u])%=mod;
			}
			if(i>=2)(dp[i][u]+=dp[i-2][u]*(mod-(d[u]-(i!=2)))%mod)%=mod;
		}
		// cout<<i<<"\n";
		// for(int u=1;u<=n;u++)cout<<dp[i][u]<<" ";cout<<"\n";
	}
	if(k<=3){
		printf("%lld\n",dp[k][n]);
		return ;
	}
	for(int i=1;i<=3;i++){
		for(int u=1;u<=n;u++)a.e[1][id(i-1,u)]=dp[i][u];
	}
	for(int i=0;i<2;i++){
		for(int u=1;u<=n;u++)b.e[id(i+1,u)][id(i,u)]=1;
	}
	m=3*n;
	for(int u=1;u<=n;u++){
		for(int i=head[u];i;i=e[i].nxt){
			int v=e[i].to;
			b.e[id(2,v)][id(2,u)]++;
		}
		b.e[id(1,u)][id(2,u)]=mod-(d[u]-1);
	}
	// for(int i=1;i<=m;i++){
		// for(int j=1;j<=m;j++)cout<<b.e[i][j]<<" ";cout<<"\n";
	// }
	// puts("");
	b=ksm(b,k-1);
	// for(int i=1;i<=m;i++){
		// for(int j=1;j<=m;j++)cout<<b.e[i][j]<<" ";cout<<"\n";
	// }
	a=a*b;
	// for(int i=1;i<=n;i++)cout<<a.e[1][i]<<" ";puts("");
	// for(int i=1;i<=n;i++)cout<<a.e[1][i+n]<<" ";puts("");
	// for(int i=1;i<=n;i++)cout<<a.e[1][i+2*n]<<" ";puts("");
	printf("%lld\n",a.e[1][n]);
}

// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=1;
	while(T--)work();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 8900kb

input:

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

output:

2

result:

ok "2"

Test #2:

score: 0
Accepted
time: 3ms
memory: 8964kb

input:

11 11 2023
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
1 11

output:

1

result:

ok "1"

Test #3:

score: 0
Accepted
time: 7ms
memory: 8904kb

input:

7 21 1000000000
1 2
1 3
1 4
1 5
1 6
1 7
2 3
2 4
2 5
2 6
2 7
3 4
3 5
3 6
3 7
4 5
4 6
4 7
5 6
5 7
6 7

output:

405422475

result:

ok "405422475"

Test #4:

score: 0
Accepted
time: 7ms
memory: 8948kb

input:

12 56 78144853
1 2
1 3
1 4
1 6
1 7
1 9
1 10
1 11
1 12
2 4
2 5
2 6
2 8
2 9
2 10
2 11
2 12
3 4
3 5
3 6
3 7
3 8
3 9
3 11
3 12
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
5 6
5 7
5 8
5 9
5 10
5 11
5 12
6 8
6 9
6 10
7 8
7 9
7 11
7 12
8 9
8 10
8 11
8 12
9 10
9 11
9 12
10 11
11 12

output:

843326021

result:

ok "843326021"

Test #5:

score: 0
Accepted
time: 16ms
memory: 8952kb

input:

13 61 268435455
1 2
1 3
1 4
1 5
1 6
1 8
1 9
1 10
1 11
1 12
1 13
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 12
2 13
3 4
3 5
3 6
3 7
3 8
3 9
3 10
4 6
4 7
4 9
4 12
4 13
5 6
5 7
5 9
5 11
5 13
6 7
6 8
6 9
6 11
6 12
6 13
7 8
7 10
7 11
7 12
8 9
8 10
8 11
8 12
8 13
9 10
9 12
9 13
10 11
10 12
10 13
11 12
11 13
12 13

output:

69651169

result:

ok "69651169"

Test #6:

score: 0
Accepted
time: 16ms
memory: 8948kb

input:

14 79 33554431
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
2 3
2 4
2 5
2 6
2 7
2 8
2 11
2 12
2 14
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
3 14
4 5
4 6
4 7
4 8
4 9
4 11
4 12
5 6
5 7
5 10
5 11
5 12
5 13
5 14
6 7
6 8
6 9
6 10
6 11
6 12
6 13
6 14
7 8
7 9
7 10
7 11
7 12
7 13
7 14
8 10
8 11
8...

output:

793621538

result:

ok "793621538"

Test #7:

score: 0
Accepted
time: 17ms
memory: 8972kb

input:

15 92 439487671
1 2
1 3
1 5
1 7
1 8
1 9
1 10
1 11
1 13
1 14
1 15
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
2 15
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
3 14
3 15
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
4 13
4 14
4 15
5 7
5 8
5 10
5 11
5 12
5 13
5 14
6 7
6 8
6 9
6 10
6 11
6 12
6 13
6 14
6 1...

output:

196201187

result:

ok "196201187"

Test #8:

score: 0
Accepted
time: 5ms
memory: 8936kb

input:

5 10 230391930
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

output:

552614127

result:

ok "552614127"

Test #9:

score: 0
Accepted
time: 6ms
memory: 8972kb

input:

5 8 268435455
1 2
1 3
1 4
2 3
2 4
2 5
3 4
4 5

output:

666456772

result:

ok "666456772"

Test #10:

score: 0
Accepted
time: 3ms
memory: 8892kb

input:

6 13 67108863
1 2
1 3
1 4
1 5
2 4
2 5
2 6
3 4
3 5
3 6
4 5
4 6
5 6

output:

317571510

result:

ok "317571510"

Test #11:

score: 0
Accepted
time: 3ms
memory: 8932kb

input:

7 18 67108863
1 2
1 3
1 4
1 5
1 6
1 7
2 3
2 4
2 5
2 6
2 7
3 5
3 6
4 5
4 6
4 7
5 6
6 7

output:

921436359

result:

ok "921436359"

Test #12:

score: 0
Accepted
time: 9ms
memory: 8956kb

input:

11 43 115349891
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
2 3
2 6
2 7
2 8
2 9
2 11
3 4
3 5
3 8
3 9
3 10
4 5
4 6
4 7
4 8
4 9
4 11
5 6
5 7
5 9
5 10
5 11
6 7
6 9
6 10
6 11
7 8
7 9
7 10
7 11
8 9
8 11
9 10
9 11

output:

853336717

result:

ok "853336717"

Test #13:

score: 0
Accepted
time: 15ms
memory: 8888kb

input:

14 78 758166229
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
2 3
2 4
2 5
2 6
2 7
2 8
2 10
2 11
2 14
3 5
3 6
3 7
3 8
3 9
3 10
3 11
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 13
4 14
5 6
5 7
5 8
5 9
5 10
5 11
5 13
5 14
6 7
6 8
6 9
6 10
6 11
6 12
6 14
7 8
7 9
7 10
7 11
7 12
7 13
7 14
8 9
8 10
8 11
8 1...

output:

949739691

result:

ok "949739691"

Test #14:

score: 0
Accepted
time: 573ms
memory: 8932kb

input:

52 51 376665160
1 2
1 3
2 4
4 5
5 6
5 7
3 8
5 9
5 10
5 11
6 12
4 13
2 14
6 15
14 16
9 17
8 18
15 19
11 20
9 21
1 22
21 23
3 24
24 25
24 26
10 27
7 28
24 29
16 30
6 31
4 32
5 33
10 34
33 35
32 36
19 37
29 38
18 39
17 40
13 41
39 42
3 43
12 44
34 45
20 46
38 47
27 48
43 49
5 50
6 51
4 52

output:

0

result:

ok "0"

Test #15:

score: 0
Accepted
time: 10ms
memory: 8932kb

input:

29 28 4
1 2
1 3
2 4
1 5
3 6
3 7
6 8
4 9
3 10
6 11
10 12
4 13
3 14
9 15
6 16
14 17
16 18
11 19
19 20
8 21
6 22
18 23
18 24
3 25
2 26
8 27
1 28
8 29

output:

1

result:

ok "1"

Test #16:

score: -100
Time Limit Exceeded

input:

99 98 33554431
46 94
29 46
29 75
50 75
50 61
6 61
6 10
10 49
38 49
38 86
37 86
37 66
31 66
31 71
41 71
41 67
22 67
22 52
52 62
62 74
74 89
53 89
53 91
69 91
40 69
40 97
45 97
9 45
9 18
18 23
23 25
25 43
43 92
3 92
3 5
5 28
28 58
19 58
17 19
17 80
4 80
4 56
24 56
21 24
1 21
1 95
51 95
36 51
36 96
20 ...

output:


result: