結果

問題 No.92 逃走経路
ユーザー nayutanayuta
提出日時 2020-01-04 17:30:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 926 bytes
コンパイル時間 1,593 ms
コンパイル使用メモリ 174,476 KB
実行使用メモリ 10,144 KB
最終ジャッジ日時 2024-05-02 08:30:05
合計ジャッジ時間 14,046 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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];
bool ans[110];
vector<vector<edge>> G;

void dfs(int v, int pv, int k = 0){
    if(k == K){
        ans[v] = true;
        return ;
    }
    for(auto nv : G[v]){
        if(d[k] != nv.cost) continue;
        dfs(nv.to, v, k + 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