結果

問題 No.92 逃走経路
ユーザー tokizotokizo
提出日時 2020-02-15 11:52:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 154 ms / 5,000 ms
コード長 1,388 bytes
コンパイル時間 1,816 ms
コンパイル使用メモリ 168,080 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-16 03:09:07
合計ジャッジ時間 3,150 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 6 ms
6,944 KB
testcase_06 AC 4 ms
6,944 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 11 ms
6,940 KB
testcase_10 AC 75 ms
6,944 KB
testcase_11 AC 86 ms
6,944 KB
testcase_12 AC 154 ms
6,944 KB
testcase_13 AC 4 ms
6,940 KB
testcase_14 AC 15 ms
6,940 KB
testcase_15 AC 44 ms
6,940 KB
testcase_16 AC 39 ms
6,944 KB
testcase_17 AC 62 ms
6,940 KB
testcase_18 AC 29 ms
6,944 KB
testcase_19 AC 14 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int N = 110;
const int K = 1010;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, m, k;
    cin >> n >> m >> k;
    vector<int> A(m), B(m), C(m), D(k);
    for(int i = 0; i < m; i++){
        cin >> A[i] >> B[i] >> C[i];
        A[i]--;
        B[i]--;
    }
    for(int i = 0; i < k; i++){
        cin >> D[i];
    }

    bool dp[K][N] = {}; // dp[i][j] ... i 回目の移動で町 j にいるか
    
    // 0 回目の移動:どの町でもありうる
    for(int i = 0; i < n; i++){
        dp[0][i] = true;
    }

    for(int i = 1; i <= k; i++){
        for(int j = 0; j < n; j++){
            if(!dp[i - 1][j]) continue; // i - 1 回目の移動で町 j にいない
            for(int l = 0; l < m; l++){ // 町 j から伸びている道路に対して、通行料金が D[i - 1] であるものを見つける
                if(D[i - 1] == C[l] && (j == A[l] || j == B[l])){
                    if(j == A[l]) dp[i][B[l]] = true;
                    else if(j == B[l]) dp[i][A[l]] = true;
                }
            }
        }
    }

    vector<int> Ans;
    for(int i = 0; i < n; i++){
        if(dp[k][i]){
            Ans.push_back(i + 1);
        }
    }

    cout << (int)Ans.size() << endl;
    for(auto x : Ans){
        cout << x << ' ';
    }
    cout << endl;

    return 0;
}
0