結果

問題 No.92 逃走経路
ユーザー MisterMister
提出日時 2020-04-12 04:33:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,415 bytes
コンパイル時間 781 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 17:44:20
合計ジャッジ時間 2,013 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <numeric>
#include <vector>

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

void solve() {
    int n, m, k;
    std::cin >> n >> m >> k;

    Graph<> graph(n);
    while (m--) {
        int u, v, c;
        std::cin >> u >> v >> c;
        --u, --v;
        graph[u].emplace_back(u, v, c);
        graph[v].emplace_back(v, u, c);
    }

    std::vector<bool> dp(n, true);
    auto ndp = dp;

    while (k--) {
        int d;
        std::cin >> d;

        std::fill(ndp.begin(), ndp.end(), false);
        for (int v = 0; v < n; ++v) {
            if (!dp[v]) continue;

            for (auto e : graph[v]) {
                if (e.cost == d) ndp[e.dst] = true;
            }
        }

        std::swap(dp, ndp);
    }

    std::cout << std::accumulate(dp.begin(), dp.end(), 0) << std::endl;
    for (int v = 0; v < n; ++v) {
        if (dp[v]) std::cout << v + 1 << " ";
    }
    std::cout << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0