結果

問題 No.762 PDCAパス
ユーザー Mayimg
提出日時 2019-02-22 13:46:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 697 bytes
コンパイル時間 1,796 ms
コンパイル使用メモリ 195,044 KB
最終ジャッジ日時 2025-01-06 21:21:14
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34 TLE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, m;
string s, t = "PDCA";
vector<int> g[100005];
int dfs(int cur, int depth) {
	if (s[cur] != t[depth]) return 0;
	else {
		if (depth == 3) return 1;
		int res = 0;
		for (int nbr : g[cur]) {
			res += dfs(nbr, depth + 1);
			res %= mod;
		}
		return res;
	}
}
signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	cin >> s;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'P') ans = ans + dfs(i, 0) % mod;
	}
	cout << ans << endl;
	return 0;	
}
0