voiddij(){ memset(dis, 0x3f, sizeof(dis)); priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q; q.push(make_pair(0, 1)); dis[1] = 0; cnt[1] = 1; while (q.size()) { int u = q.top().second; q.pop(); if (vis[u]) continue; vis[u] = true; for (int i = head[u]; i; i = es[i].next) { int v = es[i].v; if (!vis[v] && dis[v] > dis[u] + 1) { dis[v] = dis[u] + 1; cnt[v] = cnt[u]; q.push(make_pair(dis[v], v)); } elseif (dis[v] == dis[u] + 1) { cnt[v] = (cnt[v] + cnt[u]) % MOD; } } } }
intmain(){ scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); add(u, v); } dij(); printf("%lld\n", cnt[n]); return0; }
set<vector<string>> st; vector<string> s; int f[4][2] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} }; int n, k, res;
voiddfs(int now){ if (st.find(s) != st.end()) return; st.insert(s); if (now == k) return (void)(++res); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (s[i][j] != '.') continue; bool flag = false; for (int k = 0; k < 4 && !flag; k++) { int nx = i + f[k][0]; int ny = j + f[k][1]; if (nx >= 0 && nx < n && ny >= 0 && ny < n && s[nx][ny] == '@') flag = true; } if (!flag) continue; s[i][j] = '@'; dfs(now + 1); s[i][j] = '.'; } } }
intmain(){ cin >> n >> k; s = vector<string>(n); for (auto& v: s) cin >> v; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (s[i][j] == '.') { s[i][j] = '@'; dfs(1); s[i][j] = '.'; } } } cout << res << "\n"; return0; }