結果

問題 No.92 逃走経路
ユーザー RubikunRubikun
提出日時 2019-06-17 05:21:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 171 ms / 5,000 ms
コード長 1,275 bytes
コンパイル時間 2,085 ms
コンパイル使用メモリ 168,976 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 03:43:05
合計ジャッジ時間 3,781 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007;

struct way{
    int a;
    int b;
    int len;
};

int main(){

    int N,M,K;cin>>N>>M>>K;
    vector<way> S(M);
    vector<int> D(K);
    for(int i=0;i<M;i++){
        cin>>S[i].a>>S[i].b>>S[i].len;
    }
    for(int i=0;i<K;i++){
        cin>>D[i];
    }
    bool dp[K+1][N+1];
    for(int i=0;i<K+1;i++){
        for(int j=0;j<N+1;j++){
            dp[i][j]=0;
        }
    }
    for(int i=0;i<M;i++){
        if(S[i].len==D[0]){
            dp[1][S[i].a]=1;
            dp[1][S[i].b]=1;
        }
    }
    for(int i=1;i<K;i++){
        for(int j=1;j<N+1;j++){
            for(int k=0;k<M;k++){
                if(S[k].len==D[i]){
                    if(dp[i][S[k].a]) dp[i+1][S[k].b]=1;
                    if(dp[i][S[k].b]) dp[i+1][S[k].a]=1;
                }
            }
        }
    }
    int cnt=0;
    for(int i=1;i<=N;i++){
        if(dp[K][i]){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    bool flag=true;
    for(int i=1;i<=N;i++){
        if(dp[K][i]){
            if(flag){
                cout<<i;
                flag=false;
            }
            else cout<<" "<<i;
        }
    }
    cout<<endl;
}
0