結果

問題 No.92 逃走経路
ユーザー Kutimoti_T
提出日時 2018-01-10 23:23:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,305 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 70,508 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 17:08:13
合計ジャッジ時間 1,475 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <sstream>
using namespace std;

#define FOR(i, s, e) for (int i = (s); i <= (e); i++)


int N;
int M;
int K;

struct edge{
    int a;
    int b;
    int cost;
};

edge edges[1000];

int d[1000];

bool dp[1010][110];


int main()
{
    cin >> N >> M >> K;

    FOR(i,0,M - 1)
    {
        int a,b,c;
        cin >> a >> b >> c;

        edges[i].a = a;
        edges[i].b = b;
        edges[i].cost = c;
    }

    FOR(i,0,K - 1)
    {
        cin >> d[i];
    }

    FOR(i,0,1009)
    {
        FOR(j,0,109)
        {
            dp[i][j] = false;
        }
    }

    FOR(i,0,109)
    {
        dp[0][i] = true;
    }

    FOR(i,0,K - 1)
    {
        FOR(j,0,M - 1)
        {
            edge& e = edges[j];
            if(e.cost == d[i])
            {
                if(dp[i][e.b])
                    dp[i + 1][e.a] = true;
                if(dp[i][e.a])
                    dp[i + 1][e.b] = true;
            }
        }
    }

    stringstream result;
    int cou = 0;

    FOR(i,1,N)
    {
        if(dp[K][i])
        {
            result << i << " ";
            cou++;
        }
    }

    cout << cou << endl;
    cout << result.str() << endl;
    return 0;
}
0