結果

問題 No.92 逃走経路
ユーザー nukacha
提出日時 2018-05-22 11:54:01
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 75 ms / 5,000 ms
コード長 1,163 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 128,128 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-30 12:23:01
合計ジャッジ時間 2,006 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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