結果
| 問題 | No.762 PDCAパス | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-04-18 01:09:29 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 61 ms / 2,000 ms | 
| コード長 | 1,407 bytes | 
| コンパイル時間 | 961 ms | 
| コンパイル使用メモリ | 79,056 KB | 
| 最終ジャッジ日時 | 2025-01-09 21:00:27 | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 38 | 
ソースコード
#include <iostream>
#include <vector>
#include <string>
template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};
    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};
template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;
constexpr int MOD = 1000000007;
void solve() {
    int n, m;
    std::string s;
    std::cin >> n >> m >> s;
    Graph<> graph(n);
    while (m--) {
        int u, v;
        std::cin >> u >> v;
        --u, --v;
        graph[u].emplace_back(u, v);
        graph[v].emplace_back(v, u);
    }
    std::vector<int> dp(n, 0);
    for (int v = 0; v < n; ++v) {
        if (s[v] == 'P') dp[v] = 1;
    }
    auto ndp = dp;
    for (char c : std::string("DCA")) {
        std::fill(ndp.begin(), ndp.end(), 0);
        for (int v = 0; v < n; ++v) {
            if (s[v] != c) continue;
            for (auto e : graph[v]) {
                (ndp[v] += dp[e.dst]) %= MOD;
            }
        }
        std::swap(dp, ndp);
    }
    int ans = 0;
    for (auto x : dp) (ans += x) %= MOD;
    std::cout << ans << std::endl;
}
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    solve();
    return 0;
}
            
            
            
        