結果
| 問題 | No.92 逃走経路 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-03 09:27:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 5,000 ms |
| コード長 | 1,018 bytes |
| コンパイル時間 | 739 ms |
| コンパイル使用メモリ | 81,656 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-21 16:08:58 |
| 合計ジャッジ時間 | 1,501 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;
int main() {
int N, M, K;
cin >> N >> M >> K;
vector<int> a(M), b(M), c(M);
for (int i = 0; i < M; ++i) {
cin >> a[i] >> b[i] >> c[i];
--a[i], --b[i];
}
vector<int> d(K);
for (int i = 0; i < K; ++i) cin >> d[i];
vector<vector<bool>> dp(K, vector<bool>(N,false));
for (int i = 0; i < M; ++i) {
if (d[0] == c[i]) {
dp[0][a[i]] = true;
dp[0][b[i]] = true;
}
}
for (int i = 1; i < K; ++i) {
for (int j = 0; j < M; ++j) {
if (d[i] == c[j]) {
if (dp[i - 1][a[j]]) dp[i][b[j]] = true;
if (dp[i - 1][b[j]]) dp[i][a[j]] = true;
}
}
}
int res = 0;
for (int i = 0; i < N; ++i) {
if (dp[K - 1][i]) ++res;
}
cout << res << endl;
for (int i = 0; i < N; ++i) {
if (dp[K - 1][i]) cout << i + 1 << " ";
}
cout << endl;
}