1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
| #include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int INF = 1009999999;
const unsigned mod = 45989;
int getint() {
int r = 0, k = 1; char c = getchar();
for (; '0' > c || c > '9'; c = getchar()) if (c == '-') k = -1;
for (; '0' <= c && c <= '9'; c = getchar()) r = r * 10 - '0' + c;
return r * k;
}
int a, b, n, m, N;
struct Matrix_type {
unsigned a[150][150];
void init1() {
for (int i = 0; i < N; ++i)
a[i][i] = 1;
}
};
Matrix_type temp;
int t;
void mul(Matrix_type &A, Matrix_type &B) {
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j) {
temp.a[i][j] = 0;
for (int k = 0; k < N; ++k) {
temp.a[i][j] = (temp.a[i][j] + A.a[i][k] * B.a[k][j] % mod) % mod;
}
}
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
A.a[i][j] = temp.a[i][j];
}
unsigned C[150];
void mul(unsigned *A, Matrix_type &B) {
for (int j = 0; j < N; ++j) {
C[j] = 0;
for (int k = 0; k < N; ++k) {
C[j] = (C[j] + A[k] * B.a[k][j] % mod) % mod;
}
}
for (int i = 0; i < N; ++i)
A[i] = C[i];
}
Matrix_type tmp, mat;
void KSM() {
while (t) {
if (t & 1)
mul(mat, tmp);
mul(tmp, tmp);
t >>= 1;
}
}
int id[150][150], ex[150], ey[150], EX[150], EY[150], eid[150];
unsigned A[150], cnt[150];
bool cmp(int x, int y) {
return ex[x] == ex[y] ? ey[x] < ey[y] : ex[x] < ex[y];
}
int main() {
scanf("%d%d%d%d%d", &n, &m, &t, &a, &b);
if (t == 0) {
putchar('0');
} else {
++a; ++b;
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= n; ++j)
id[i][j] = -1;
int x, y;
N = m << 1;
for (int i = 0; i < m; ++i) {
scanf("%d%d", &x, &y);
++x; ++y;
ex[i<<1] = x; ey[i<<1] = y;
eid[i<<1] = i<<1;
ex[i<<1|1] = y; ey[i<<1|1] = x;
eid[i<<1|1] = i<<1|1;
}
N = m << 1; ex[N] = ey[N] = -1;
sort(eid, eid+N, cmp);
int tot = 0, Cnt = 1;
for (int i = 0; i < N; ++i) {
int j = eid[i], k = eid[i+1];
if (ex[j] == ex[k] && ey[j] == ey[k]) {
++Cnt;
} else {
EX[tot] = ex[j]; EY[tot] = ey[j];
id[ex[j]][ey[j]] = tot++;
cnt[id[ex[j]][ey[j]]] = Cnt;
Cnt = 1;
}
}
N = tot;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (EY[i] != EX[j])
tmp.a[i][j] = 0;
else {
tmp.a[i][j] = cnt[j];
if (EX[i] == EY[j])
--tmp.a[i][j];
}
}
}
for (int i = 1; i <= n; ++i)
if (id[a][i] != -1)
A[id[a][i]] = cnt[id[a][i]];
--t;
mat.init1();
KSM();
mul(A, mat);
int ans = 0;
for (int i = 1; i <= n; ++i)
if (id[i][b] != -1)
ans = (ans + A[id[i][b]]) % mod;
printf("%d", ans);
}
return 0;
}
|