結果

問題 No.92 逃走経路
ユーザー otsnskotsnsk
提出日時 2014-12-23 20:27:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 65 ms / 5,000 ms
コード長 869 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 65,584 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 21:59:22
合計ジャッジ時間 2,103 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <list>
using namespace std;

int N, M, K;
vector<list<pair<int, int>>> fee(105);
int d[1010];

bool check(int town, int di) {

    for (auto& p: fee[town]) {
        if (p.second == d[di]) {
            if (di == 0) return true;
            if (check(p.first, di-1)) return true;
        }
    }
    return false;
}

int main() {
    int a, b, c;

    cin >> N >> M >> K;
    for (int i = 0; i < M; i++) {
        cin >> a >> b >> c;
        fee[a].push_back(make_pair(b, c));
        fee[b].push_back(make_pair(a, c));
    }
    for (int i = 0; i < K; i++) {
        cin >> d[i];
    }

    vector<int> t;
    for (int i = 1; i <= N; i++) {
        if (check(i, K-1)) t.push_back(i);
    }

    cout << t.size() << "\n" << t[0];
    for (int i = 1; i < t.size(); i++) {
        cout << " " << t[i];
    }

    return 0;
}
0