結果

問題 No.762 PDCAパス
ユーザー Pachicobue
提出日時 2018-12-10 00:28:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 773 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 79,120 KB
最終ジャッジ日時 2025-01-06 18:47:17
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <set>
using ll = long long;
using P = std::pair<int, int>;
constexpr ll MOD = 1000000007;
int main()
{	
	int N, M;
	std::cin >> N >> M;
	std::string S;
	std::cin >> S;
	std::vector<P> edge;
	std::vector<int> from(N, 0),  to(N, 0);
	for (int i = 0, u, v; i < M; i++) { 
		std::cin >> u >> v, u--, v--;
		edge.push_back({ u,v }), edge.push_back({v,u});
		if (S[u] == 'P' and S[v] == 'D') {
			from[v]++;
		} else if (S[u] == 'D' and S[v] == 'P') {
			from[u]++;
		}
		if (S[u] == 'C' and S[v] == 'A') {
			to[u]++;
		} else if (S[u] == 'A' and S[v] == 'C') {
			to[v]++;
		}
	}
	ll ans = 0;
	for (const auto& e : edge) { (ans += from[e.first] * to[e.second] % MOD) %= MOD; }
	std::cout << ans << std::endl;
}

0