-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14289.cpp
More file actions
50 lines (48 loc) · 923 Bytes
/
14289.cpp
File metadata and controls
50 lines (48 loc) · 923 Bytes
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
#include<iostream>
#include<vector>
#define mod 1000000007
using namespace std;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
int n,m;
vvll multi(vvll &a , vvll &b){
vvll ret;
for(int i=0;i<n;i++){
vll r;
for(int j=0;j<n;j++){
ll tmp=0;
for(int k=0;k<n;k++){
tmp+=(a[i][k]*b[k][j]);
tmp%=mod;
}
r.push_back(tmp);
}
ret.push_back(r);
}
return ret;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>m;
int x,y,d;
vvll p(n,vll(n));
for(int i=0;i<m;i++){
cin>>x>>y;
x--;
y--;
p[x][y]=p[y][x]=1;
}
vvll ans=p;
cin>>d;
d--;
while(d>0){
if(d%2==1){
ans = multi(ans,p);
}
p = multi(p,p);
d/=2;
}
cout<<ans[0][0];
}