結果

問題 No.762 PDCAパス
コンテスト
ユーザー Mayimg
提出日時 2019-02-22 13:46:44
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 697 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,623 ms
コンパイル使用メモリ 212,484 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2026-06-07 06:59:00
合計ジャッジ時間 5,960 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 TLE * 1 -- * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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