結果

問題 No.1480 Many Complete Graphs
ユーザー KudeKude
提出日時 2021-04-16 21:58:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 2,300 bytes
コンパイル時間 4,613 ms
コンパイル使用メモリ 269,648 KB
実行使用メモリ 16,012 KB
最終ジャッジ日時 2023-09-16 02:57:57
合計ジャッジ時間 8,886 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 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
8,428 KB
testcase_14 AC 10 ms
6,636 KB
testcase_15 AC 26 ms
9,624 KB
testcase_16 AC 17 ms
7,808 KB
testcase_17 AC 16 ms
7,480 KB
testcase_18 AC 6 ms
6,056 KB
testcase_19 AC 16 ms
7,572 KB
testcase_20 AC 23 ms
8,388 KB
testcase_21 AC 16 ms
8,056 KB
testcase_22 AC 9 ms
6,000 KB
testcase_23 AC 34 ms
12,872 KB
testcase_24 AC 38 ms
11,524 KB
testcase_25 AC 52 ms
13,004 KB
testcase_26 AC 56 ms
14,812 KB
testcase_27 AC 39 ms
11,548 KB
testcase_28 AC 40 ms
14,092 KB
testcase_29 AC 43 ms
14,256 KB
testcase_30 AC 43 ms
14,016 KB
testcase_31 AC 43 ms
14,076 KB
testcase_32 AC 44 ms
14,020 KB
testcase_33 AC 44 ms
14,156 KB
testcase_34 AC 43 ms
14,012 KB
testcase_35 AC 41 ms
14,072 KB
testcase_36 AC 40 ms
14,020 KB
testcase_37 AC 43 ms
14,236 KB
testcase_38 AC 41 ms
14,004 KB
testcase_39 AC 41 ms
14,188 KB
testcase_40 AC 43 ms
14,136 KB
testcase_41 AC 42 ms
14,012 KB
testcase_42 AC 43 ms
14,212 KB
testcase_43 AC 43 ms
14,216 KB
testcase_44 AC 43 ms
14,028 KB
testcase_45 AC 43 ms
14,132 KB
testcase_46 AC 43 ms
14,020 KB
testcase_47 AC 90 ms
16,012 KB
testcase_48 AC 90 ms
15,996 KB
testcase_49 AC 90 ms
15,820 KB
testcase_50 AC 52 ms
15,476 KB
testcase_51 AC 92 ms
15,896 KB
testcase_52 AC 69 ms
15,572 KB
testcase_53 AC 67 ms
15,488 KB
testcase_54 AC 69 ms
15,620 KB
testcase_55 AC 66 ms
15,484 KB
testcase_56 AC 67 ms
15,628 KB
testcase_57 AC 45 ms
14,756 KB
testcase_58 AC 48 ms
15,200 KB
evil_aftercontest.txt AC 95 ms
27,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

const unsigned long long INF = 1002003004005006007;
template<class T>
std::vector<unsigned long long> dijkstra(std::vector<std::vector<std::pair<int,T>>>& to, int s=0) {
    struct QueElem {
        int v;
        unsigned long long c;
        bool operator<(const QueElem a) const {return c > a.c;}
        QueElem(int v, unsigned long long c): v(v), c(c) {}
    };
    std::priority_queue<QueElem> q;
    std::vector<unsigned long long> dist(to.size(), INF);
    dist[s] = 0;
    q.emplace(s, 0);
    while(!q.empty()) {
        QueElem qe = q.top(); q.pop();
        int u = qe.v;
        unsigned long long c = qe.c;
        if (c > dist[u]) continue;
        for(auto vc: to[u]) {
            int v = vc.first;
            unsigned long long nc = c + vc.second;
            if (nc < dist[v]) {
                dist[v] = nc;
                q.emplace(v, nc);
            }
        }
    }
    return dist;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, ll>>> to(n + 2 * m);
    rep(i, m) {
        ll k, c;
        cin >> k >> c;
        VI s(k);
        rep(j, k) cin >> s[j];
        int ev = n + 2 * i, ov = n + 2 * i + 1;
        for(int u: s) {
            if (u & 1) {
                to[u - 1].emplace_back(ov, u / 2);
                to[ev].emplace_back(u - 1, c + u / 2 + 1);
                to[ov].emplace_back(u - 1, c + u / 2 + 1);
            } else {
                to[u - 1].emplace_back(ev, u / 2);
                to[ev].emplace_back(u - 1, c + u / 2);
                to[ov].emplace_back(u - 1, c + u / 2 + 1);
            }
        }
    }
    auto dist = dijkstra(to);
    ll ans = dist[n - 1];
    if (ans == INF) ans = -1;
    cout << ans << '\n';
}
0