結果

問題 No.92 逃走経路
ユーザー cherrypi59cherrypi59
提出日時 2018-10-13 14:06:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 773 bytes
コンパイル時間 1,213 ms
コンパイル使用メモリ 162,656 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 20:02:52
合計ジャッジ時間 1,879 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

struct edge {int from, to, cost;};

int d[1005], dp[1005][105];

int main(){
    int n, m, k, cnt = 0; cin>>n>>m>>k;
    vector<edge> E(m);
    for(int i=0;i<m;i++) cin>>E[i].from>>E[i].to>>E[i].cost;
    for(int i=0;i<k;i++) cin>>d[i];

    for(int i=1;i<=n;i++) dp[0][i] = 1;
    for(int i=1;i<=k;i++){
        for(auto it:E){
            if(it.cost==d[i-1]&&dp[i-1][it.from]) dp[i][it.to] = 1;
            if(it.cost==d[i-1]&&dp[i-1][it.to]) dp[i][it.from] = 1;
        }
    }

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

    cout<<cnt<<endl;
    for(int it:ans) cout<<it<<' ';
    cout<<endl;
    return 0;
}
0