結果

問題 No.92 逃走経路
ユーザー nayutanayuta
提出日時 2020-01-04 18:12:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 1,158 bytes
コンパイル時間 1,820 ms
コンパイル使用メモリ 175,212 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 08:32:21
合計ジャッジ時間 2,702 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 13 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 13 ms
5,376 KB
testcase_11 AC 13 ms
5,376 KB
testcase_12 AC 13 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 6 ms
5,376 KB
testcase_17 AC 6 ms
5,376 KB
testcase_18 AC 6 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

struct edge{
    int to, cost;
    edge(int a, int b){
        to = a, cost = b;
    }
};

int N, M, K, d[1010], dp[1010][110]; //dp[k][v] := k回目にvにいる時到達可能かどうか;
bool ans[110];
vector<vector<edge>> G;

void dfs(int v, int pv, int k = 0){
    if(dp[k][v] != 0) return ;
    if(k == K){
        ans[v] = true;
        dp[k][v] = 1;
        return ;
    }
    bool ng = true;
    for(auto nv : G[v]){
        if(d[k] != nv.cost) continue;
        dfs(nv.to, v, k + 1);
        dp[k][v] = dp[k+1][nv.to];
        ng = false;
    }
    if(ng) dp[k][v] = -1;
}


int main(){
    cin >> N >> M >> K;
    G.assign(N, vector<edge>());
    for(int i = 0; i < M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }
    for(int i = 0; i < K; i++) cin >> d[i];

    for(int i = 0; i < N; i++){
        dfs(i, -1);
    }

    cout << count(ans, ans+N, true) << endl;
    for(int i = 0; i < N; i++){
        if(ans[i]){
            cout << i + 1 << " ";
        }
    }
    cout << endl;

    return 0;
}
0