結果

問題 No.92 逃走経路
ユーザー nukachanukacha
提出日時 2018-05-22 11:54:01
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 1,163 bytes
コンパイル時間 1,027 ms
コンパイル使用メモリ 94,484 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 10:43:11
合計ジャッジ時間 2,922 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 9 ms
4,380 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 11 ms
4,380 KB
testcase_10 AC 82 ms
4,376 KB
testcase_11 AC 77 ms
4,380 KB
testcase_12 AC 32 ms
4,384 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 16 ms
4,376 KB
testcase_15 AC 29 ms
4,380 KB
testcase_16 AC 28 ms
4,380 KB
testcase_17 AC 42 ms
4,380 KB
testcase_18 AC 37 ms
4,380 KB
testcase_19 AC 15 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <vector>
#include <map>

using namespace std;

int N, M, K;
vector<map<int, vector<int>> > fee(1000);
int d[1000] = {0};

int main() {
    cin >> N >> M >> K;
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        fee[a-1][b-1].push_back(c);
        fee[b-1][a-1].push_back(c);
    }
    for (int i = 0; i < K; i++) {
        cin >> d[i];
    }
    set<int> candidate;
    for (int i = 0; i < N; i++) {
        candidate.insert(i);
    }
    for (int i = 0; i < K; i++) {
        set<int> new_candidate;
        for (int now: candidate) {
            for (auto next: fee[now]) {
                for (int f: next.second) {
                    if (d[i] == f) {
                        new_candidate.insert(next.first);
                    }
                }
            }
        }
        candidate = new_candidate;
    }
    cout << candidate.size() << endl;
    for (auto itr = candidate.begin(); itr != candidate.end(); itr++) {
        cout << *itr + 1;
        if (itr != --candidate.end()) {
            cout << " ";
        } else {
            cout << endl;
        }
    }
}
0