結果

問題 No.1480 Many Complete Graphs
ユーザー MisterMister
提出日時 2021-04-16 21:37:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 2,583 bytes
コンパイル時間 798 ms
コンパイル使用メモリ 86,260 KB
実行使用メモリ 16,632 KB
最終ジャッジ日時 2023-09-16 02:54:34
合計ジャッジ時間 5,557 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 14 ms
7,988 KB
testcase_14 AC 10 ms
6,372 KB
testcase_15 AC 30 ms
9,644 KB
testcase_16 AC 16 ms
8,016 KB
testcase_17 AC 17 ms
7,600 KB
testcase_18 AC 6 ms
5,968 KB
testcase_19 AC 18 ms
7,488 KB
testcase_20 AC 26 ms
8,492 KB
testcase_21 AC 18 ms
8,004 KB
testcase_22 AC 9 ms
5,744 KB
testcase_23 AC 34 ms
12,744 KB
testcase_24 AC 41 ms
11,484 KB
testcase_25 AC 60 ms
13,900 KB
testcase_26 AC 62 ms
14,568 KB
testcase_27 AC 41 ms
11,432 KB
testcase_28 AC 55 ms
14,900 KB
testcase_29 AC 57 ms
14,852 KB
testcase_30 AC 53 ms
14,800 KB
testcase_31 AC 49 ms
14,048 KB
testcase_32 AC 53 ms
14,896 KB
testcase_33 AC 54 ms
14,920 KB
testcase_34 AC 51 ms
14,916 KB
testcase_35 AC 52 ms
14,832 KB
testcase_36 AC 50 ms
14,836 KB
testcase_37 AC 53 ms
14,880 KB
testcase_38 AC 50 ms
14,904 KB
testcase_39 AC 49 ms
13,828 KB
testcase_40 AC 50 ms
14,840 KB
testcase_41 AC 48 ms
13,856 KB
testcase_42 AC 54 ms
14,852 KB
testcase_43 AC 52 ms
14,924 KB
testcase_44 AC 48 ms
13,840 KB
testcase_45 AC 53 ms
14,904 KB
testcase_46 AC 50 ms
13,756 KB
testcase_47 AC 91 ms
15,712 KB
testcase_48 AC 94 ms
15,640 KB
testcase_49 AC 98 ms
15,720 KB
testcase_50 AC 51 ms
15,412 KB
testcase_51 AC 91 ms
15,656 KB
testcase_52 AC 69 ms
15,136 KB
testcase_53 AC 69 ms
15,132 KB
testcase_54 AC 75 ms
15,848 KB
testcase_55 AC 68 ms
15,232 KB
testcase_56 AC 74 ms
15,200 KB
testcase_57 AC 42 ms
14,576 KB
testcase_58 AC 54 ms
16,632 KB
evil_aftercontest.txt AC 107 ms
31,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Graph/dijkstra.hpp"

#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/heap_alias.hpp"

#include <queue>

template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Graph/graph.hpp"

#include <vector>

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;

    Edge() = default;
    Edge(int src, int dst, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

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

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

    void span(bool direct, int src, int dst, Cost cost = 1) {
        (*this)[src].emplace_back(src, dst, cost);
        if (!direct) (*this)[dst].emplace_back(dst, src, cost);
    }
};
#line 5 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Graph/dijkstra.hpp"

template <class Cost>
std::vector<Cost> dijkstra(const Graph<Cost>& graph, int s) {
    std::vector<Cost> dist(graph.size(), -1);
    dist[s] = 0;
    MinHeap<std::pair<Cost, int>> que;
    que.emplace(0, s);

    while (!que.empty()) {
        auto [d, v] = que.top();
        que.pop();
        if (d > dist[v]) continue;

        for (const auto& e : graph[v]) {
            if (dist[e.dst] != -1 &&
                dist[e.dst] <= dist[v] + e.cost) continue;
            dist[e.dst] = dist[v] + e.cost;
            que.emplace(dist[e.dst], e.dst);
        }
    }

    return dist;
}
#line 2 "main.cpp"
#include <iostream>

using namespace std;
using lint = long long;

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

    Graph<lint> graph(n + m * 2);
    for (int i = 0; i < m; ++i) {
        int k;
        lint c;
        cin >> k >> c;

        int r = n + i * 2;
        while (k--) {
            int v;
            cin >> v;

            graph.span(true, v - 1, r, (v + 1) / 2);
            graph.span(true, r, v - 1, (v + 1) / 2 + c);

            if (v % 2 != 0) {
                graph.span(true, v - 1, r + 1, (v + 1) / 2);
                graph.span(true, r + 1, v - 1, (v + 1) / 2 + c - 1);
            }
        }
    }

    cout << dijkstra(graph, 0)[n - 1] << "\n";
}

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

    solve();

    return 0;
}
0