Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- #include <cstdio>
- #include <queue>
- #include <map>
- #include <cmath>
- #include <algorithm>
- #include <cassert>
- using namespace std;
- #define int int64_t
- int n,m;
- vector<int> t;
- const int N=32;
- const int P=32;
- const int Base=1e9+7;
- int dp[P][N][N];
- int32_t main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- freopen("numwords.in", "r", stdin);
- freopen("numwords.out", "w", stdout);
- cin >> n >> m;
- for(int i=0;i<m;i++){
- int u,v;
- char c;
- cin >> u >> c >> v;
- u--;v--;
- dp[0][u][v]++;
- }
- // for(int i=0;i<n;i++){
- // for(int j=0;j<n;j++){
- // cout << dp[0][i][j] << ' ';
- // }
- // cout << endl;
- // }
- // cout << endl;
- int r;
- cin >> r;
- t.resize(r);
- for(int i=0;i<r;i++) {
- cin >> t[i];
- t[i]--;
- }
- int p;
- cin >> p;
- for(int cur=1;cur<P;cur++){
- for(int i=0;i<n;i++){
- for(int j=0;j<n;j++){
- for(int e=0;e<n;e++) {
- dp[cur][i][j] += dp[cur-1][i][e] * dp[cur-1][e][j];
- dp[cur][i][j] %= Base;
- }
- // cout << dp[cur][i][j] << ' ';
- }
- // cout << endl;
- }
- //cout<< endl;
- }
- vector<int> res(n);
- res[0]=1;
- for(int cur=0;cur<P;cur++){
- if(((1 << cur) | p) == p){
- vector<int> nextt(n);
- for(int i=0;i<n;i++){
- for(int j=0;j<n;j++){
- nextt[j] += res[i]*dp[cur][i][j];
- nextt[j] %=Base;
- }
- }
- res=nextt;
- }
- }
- // for(int i=0;i<n;i++){
- // for(int j=0;j<n;j++){
- // cout << res[i][j] << ' ' ;
- // }
- // cout << endl;
- // }
- int ans =0;
- for(int i=0;i<t.size();i++){
- ans += res[t[i]];
- }
- ans %= Base;
- cout << ans << endl;
- return 0;
- }
- /*
- 3 2
- 1 0 1
- 0 2 1
- 1
- 1 2
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement