inlinelonglongnis(int c, int i){ staticint ret; ret = f[c][0] - f[c][i]; return ret < 0 ? ret + MOD : ret; }
voiddfs(int t, int p){ int len = a[t].size(), c; for (int i = 0; i < len; i++) if (a[t][i] != p) { dfs(a[t][i], t); } for (int i = 1; i <= m; i++) { if (can[t][i]) f[t][i] = 1; elsecontinue ; for (int j = 0; j < len; j++) { if ((c = a[t][j]) == p) continue ; f[t][i] *= nis(c, i); f[t][i] %= MOD; } } for (int i = 1; i <= m; i++) { f[t][0] += f[t][i]; f[t][0] %= MOD; } }
while (cin >> n >> m) { memset(f, 0, sizeof(f)); for (int i = 1; i <= n; i++) a[i].clear(); for (int i = 1; i < n; i++) { cin >> s >> t; a[s].push_back(t); a[t].push_back(s); } for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { cin >> t; can[i][j] = t; }
inlinevoidinit(mat &x, bool I){ x.resize(n + 1); for (int i = 0; i <= n; i++) x[i].resize(n + 1); for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) x[i][j] = 0; if (I) for (int i = 0; i <= n; i++) x[i][i] = 1; }
inline mat mul(const mat &a, const mat &b){ mat c; init(c, false); for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) { for (int k = 0; k <= n; k++) { c[i][j] += (a[i][k] * b[k][j]) % MOD; c[i][j] %= MOD; } } return c; }
inline mat quick_mod(mat a, int q){ mat c; init(c, true); while (q) { if (q & 1) c = mul(a, c); a = mul(a, a); q >>= 1; } return c; }
inlinevoidprint(const mat &a){ for (int i = 0; i <= n; i++, cout << endl) for (int j = 0; j <= n; j++) cout << a[i][j] << " "; }
intmain(){ int x, y, t; cin >> n >> m; mat a; init(a, false); while (m--) { cin >> x >> y; x--, y--; a[x][y] = 1; a[y][x] = 1; } cin >> t;
for (int i = 0; i < n; i++) a[n - 1][i] = 0; a[n - 1][n] = 1; a[n][n] = 1;
a = quick_mod(a, t); a[0][n] += a[0][n - 1]; cout << a[0][n] % MOD << endl;
return0; }
2017 Wuhan University Programming Contest (Online Round) 划水