結果

問題 No.92 逃走経路
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-06-21 17:23:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,784 bytes
コンパイル時間 2,167 ms
コンパイル使用メモリ 168,068 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 23:39:35
合計ジャッジ時間 2,853 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os;
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    struct Edge {
        int from, to, cost;
        Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
    };

    int N, M, K;
    vector<Edge> E;
    vector<int> D;
    void input() {
        cin >> N >> M >> K;
        E.clear();
        for (int i = 0; i < M; i++) {
            int a, b, c; cin >> a >> b >> c;
            a--; b--;
            E.push_back(Edge(a, b, c));
        }
        D.clear(); D.resize(K); cin >> D;
    }

    void solve() {
        vector<bool> P[2];
        P[0] = vector<bool>(N, true);
        P[1] = vector<bool>(N, false);
        for (int k = 0; k < K; k++) {
            int d = D[k];
            for (int i = 0; i < M; i++) {
                const Edge& e = E[i];
                if (e.cost == d) {
                    if (P[0][e.from]) P[1][e.to] = true;
                    if (P[0][e.to]) P[1][e.from] = true;
                }
            }
            swap(P[0], P[1]);
            fill(P[1].begin(), P[1].end(), false);
        }
        vector<int> ans;
        for (int i = 0; i < N; i++) {
            if (P[0][i]) {
                ans.push_back(i + 1);
            }
        }
        cout << ans.size() << endl;
        cout << ans << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

0