結果

問題 No.92 逃走経路
ユーザー  nemunemu nemunemu
提出日時 2023-05-03 09:26:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,014 bytes
コンパイル時間 830 ms
コンパイル使用メモリ 80,468 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-13 22:03:47
合計ジャッジ時間 1,974 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 << " ";
    }
    cout << endl;
}
0