結果
問題 | No.762 PDCAパス |
ユーザー |
|
提出日時 | 2019-09-02 21:02:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 85 ms / 2,000 ms |
コード長 | 1,173 bytes |
コンパイル時間 | 1,568 ms |
コンパイル使用メモリ | 171,356 KB |
実行使用メモリ | 9,728 KB |
最終ジャッジ日時 | 2024-12-17 16:27:16 |
合計ジャッジ時間 | 4,717 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main() {int N, M;cin >> N >> M;string S;cin >> S;vector<vector<int>> adj(N);for (int i = 0; i < M; i++) {int u, v;cin >> u >> v;u--;v--;adj[u].push_back(v);adj[v].push_back(u);}long long DP[N] = {};for (int i = 0; i < N; i++) {if (S[i] == 'P') {DP[i] = 1;}}for (int i = 0; i < N; i++) {if (S[i] == 'D') {for (const auto& x : adj[i]) {if (S[x] == 'P') {DP[i] += DP[x];}}}}for (int i = 0; i < N; i++) {if (S[i] == 'C') {for (const auto& x : adj[i]) {if (S[x] == 'D') {DP[i] += DP[x];}}}}long long ans = 0;for (int i = 0; i < N; i++) {if (S[i] == 'A') {for (const auto& x : adj[i]) {if (S[x] == 'C') {ans += DP[x];}}}}cout << ans % 1000000007 << endl;}