結果

問題 No.1480 Many Complete Graphs
ユーザー firiexpfiriexp
提出日時 2021-04-16 22:55:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 2,237 bytes
コンパイル時間 1,157 ms
コンパイル使用メモリ 113,196 KB
実行使用メモリ 16,024 KB
最終ジャッジ日時 2023-09-16 03:00:10
合計ジャッジ時間 5,790 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 16 ms
8,320 KB
testcase_14 AC 12 ms
6,524 KB
testcase_15 AC 29 ms
9,696 KB
testcase_16 AC 17 ms
8,004 KB
testcase_17 AC 16 ms
7,540 KB
testcase_18 AC 6 ms
6,008 KB
testcase_19 AC 18 ms
7,664 KB
testcase_20 AC 25 ms
8,436 KB
testcase_21 AC 18 ms
8,132 KB
testcase_22 AC 10 ms
5,720 KB
testcase_23 AC 38 ms
12,920 KB
testcase_24 AC 42 ms
11,528 KB
testcase_25 AC 60 ms
13,128 KB
testcase_26 AC 60 ms
14,868 KB
testcase_27 AC 44 ms
11,568 KB
testcase_28 AC 48 ms
14,088 KB
testcase_29 AC 49 ms
14,216 KB
testcase_30 AC 47 ms
14,072 KB
testcase_31 AC 45 ms
14,208 KB
testcase_32 AC 47 ms
14,212 KB
testcase_33 AC 46 ms
14,028 KB
testcase_34 AC 46 ms
14,088 KB
testcase_35 AC 44 ms
14,184 KB
testcase_36 AC 47 ms
14,064 KB
testcase_37 AC 46 ms
14,104 KB
testcase_38 AC 46 ms
14,052 KB
testcase_39 AC 46 ms
14,204 KB
testcase_40 AC 46 ms
14,148 KB
testcase_41 AC 46 ms
14,180 KB
testcase_42 AC 47 ms
14,032 KB
testcase_43 AC 47 ms
14,208 KB
testcase_44 AC 46 ms
14,032 KB
testcase_45 AC 47 ms
14,208 KB
testcase_46 AC 47 ms
14,208 KB
testcase_47 AC 101 ms
15,972 KB
testcase_48 AC 101 ms
15,996 KB
testcase_49 AC 100 ms
15,876 KB
testcase_50 AC 62 ms
15,452 KB
testcase_51 AC 104 ms
16,024 KB
testcase_52 AC 76 ms
15,596 KB
testcase_53 AC 74 ms
15,528 KB
testcase_54 AC 73 ms
15,600 KB
testcase_55 AC 77 ms
15,516 KB
testcase_56 AC 75 ms
15,560 KB
testcase_57 AC 64 ms
14,732 KB
testcase_58 AC 61 ms
15,252 KB
evil_aftercontest.txt AC 118 ms
27,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <typename T>
struct edge {
    int from, to; T cost;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template <typename T>
vector<T> dijkstra(int s,vector<vector<edge<T>>> &G){
    auto n = G.size();
    vector<T> d(n, INF<T>);
    priority_queue<pair<T, int>,vector<pair<T, int>>,greater<>> Q;
    d[s] = 0;
    Q.emplace(0, s);
    while(!Q.empty()){
        T cost; int i;
        tie(cost, i) = Q.top(); Q.pop();
        if(d[i] < cost) continue;
        for (auto &&e : G[i]) {
            auto cost2 = cost + e.cost;
            if(d[e.to] <= cost2) continue;
            d[e.to] = cost2;
            Q.emplace(d[e.to], e.to);
        }
    }
    return d;
}


template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "{";
    for (int i = 0; i < v.size(); ++i) {
        if(i) os << ", ";
        os << v[i];
    }
    return os << "}";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "{" << p.first << ", " << p.second << "}";
}


int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<edge<ll>>> G(n+2*m);
    int id = n;
    for (int i = 0; i < m; ++i) {
        int k, c;
        cin >> k >> c;
        for (int j = 0; j < k; ++j) {
            int x;
            scanf("%d", &x);
            if(x&1) {
                G[x-1].emplace_back(id, x/2+1);
                G[id].emplace_back(x-1, x/2+c);
                G[id+1].emplace_back(x-1, x/2+c+1);
            } else {
                G[x-1].emplace_back(id+1, x/2);
                G[id].emplace_back(x-1, x/2+c);
                G[id+1].emplace_back(x-1, x/2+c);
            }
        }
        id += 2;
    }
    ll ans = dijkstra(0, G)[n-1];
    if(ans == INF<ll>) puts("-1");
    else cout << ans << "\n";
    return 0;
}
0