結果
| 問題 | No.762 PDCAパス | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-05-05 02:54:50 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 103 ms / 2,000 ms | 
| コード長 | 1,106 bytes | 
| コンパイル時間 | 1,666 ms | 
| コンパイル使用メモリ | 161,544 KB | 
| 実行使用メモリ | 11,008 KB | 
| 最終ジャッジ日時 | 2024-06-25 15:35:46 | 
| 合計ジャッジ時間 | 4,739 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 38 | 
ソースコード
#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/
ll N, M;
vector<ll> g[MAX];
ll a[MAX];
ll mem[MAX];
ll dfs(ll u) {
  if(a[u]==3) return 1;
  if(mem[u]!=-1) return mem[u];
  
  ll res=0;
  for(auto v:g[u]) if(a[u]+1==a[v]) {
    moC(res, +, dfs(v));
  }
  
  return mem[u]=res;
}
int main(void) {
  ll i, j, k;
  
  cin >> N >> M;
  string s;
  cin >> s;
  
  for(i=0; i<N; i++) {
    if(s[i]=='P') a[i]=0;
    if(s[i]=='D') a[i]=1;
    if(s[i]=='C') a[i]=2;
    if(s[i]=='A') a[i]=3;
  }
  
  for(i=0; i<M; i++) {
    ll u, v;
    cin >> u >> v; u--; v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  
  memset(mem, -1, sizeof(mem));
  
  ll ans=0;
  for(i=0; i<N; i++) if(a[i]==0) moC(ans, +, dfs(i));
  pt(ans);
  
  
}
 
 
            
            
            
        