結果

問題 No.762 PDCAパス
ユーザー eQe
提出日時 2020-05-05 02:42:32
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 1,009 bytes
コンパイル時間 1,987 ms
コンパイル使用メモリ 162,308 KB
実行使用メモリ 14,880 KB
最終ジャッジ日時 2024-06-25 15:14:17
合計ジャッジ時間 9,030 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 TLE * 1 -- * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 dfs(ll u) {
  if(a[u]==3) return 1;
  
  ll res=0;
  for(auto v:g[u]) if(a[u]+1==a[v]) moC(res, +, dfs(v));
  
  return 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);
  }
  
  ll ans=0;
  for(i=0; i<N; i++) if(a[i]==0) moC(ans, +, dfs(i));
  pt(ans);
  
  
}
 
 
0