結果

問題 No.1480 Many Complete Graphs
ユーザー milanis48663220milanis48663220
提出日時 2021-05-23 18:40:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 2,334 bytes
コンパイル時間 1,231 ms
コンパイル使用メモリ 129,004 KB
実行使用メモリ 37,096 KB
最終ジャッジ日時 2024-04-20 03:51:18
合計ジャッジ時間 5,925 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 16 ms
11,136 KB
testcase_14 AC 10 ms
8,192 KB
testcase_15 AC 23 ms
12,416 KB
testcase_16 AC 16 ms
10,368 KB
testcase_17 AC 13 ms
9,344 KB
testcase_18 AC 5 ms
7,680 KB
testcase_19 AC 14 ms
9,344 KB
testcase_20 AC 21 ms
9,984 KB
testcase_21 AC 16 ms
10,752 KB
testcase_22 AC 10 ms
7,040 KB
testcase_23 AC 32 ms
17,780 KB
testcase_24 AC 30 ms
12,672 KB
testcase_25 AC 40 ms
16,512 KB
testcase_26 AC 44 ms
18,176 KB
testcase_27 AC 31 ms
13,056 KB
testcase_28 AC 45 ms
21,444 KB
testcase_29 AC 45 ms
21,316 KB
testcase_30 AC 43 ms
20,908 KB
testcase_31 AC 44 ms
21,212 KB
testcase_32 AC 43 ms
21,316 KB
testcase_33 AC 45 ms
20,992 KB
testcase_34 AC 44 ms
21,316 KB
testcase_35 AC 43 ms
20,736 KB
testcase_36 AC 42 ms
20,864 KB
testcase_37 AC 44 ms
21,340 KB
testcase_38 AC 43 ms
20,736 KB
testcase_39 AC 42 ms
21,336 KB
testcase_40 AC 45 ms
20,872 KB
testcase_41 AC 45 ms
20,972 KB
testcase_42 AC 45 ms
21,316 KB
testcase_43 AC 46 ms
21,440 KB
testcase_44 AC 43 ms
21,444 KB
testcase_45 AC 49 ms
21,440 KB
testcase_46 AC 45 ms
21,452 KB
testcase_47 AC 107 ms
32,740 KB
testcase_48 AC 103 ms
32,716 KB
testcase_49 AC 102 ms
32,936 KB
testcase_50 AC 60 ms
32,360 KB
testcase_51 AC 102 ms
32,840 KB
testcase_52 AC 72 ms
26,032 KB
testcase_53 AC 67 ms
26,168 KB
testcase_54 AC 69 ms
26,044 KB
testcase_55 AC 73 ms
26,016 KB
testcase_56 AC 72 ms
26,176 KB
testcase_57 AC 65 ms
37,096 KB
testcase_58 AC 70 ms
29,584 KB
evil_aftercontest.txt AC 148 ms
56,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;
const ll INF = 1e+15;

typedef pair<ll, int> P;

struct edge{
    int to;
    ll cost;
};

vector<ll> dijkstra(int s, vector<vector<edge>> G){
    priority_queue<P, vector<P>, greater<P>> que;
    int n = G.size();
    vector<ll> d(n, INF);
    d[s] = 0;
    que.push(P(0, s));
    while(!que.empty()){
        P p = que.top();que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[v] + e.cost < d[e.to]){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    return d;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m; cin >> n >> m;
    auto to_idx = [&](int i, bool s, bool even){
        int x = ((s ? 0 : 1) << 1) + (even ? 0 : 1);
        return n+4*i+x+1;
    };
    vector<vector<edge>> g(n+4*m+1);
    for(int i = 0; i < m; i++){
        int k; cin >> k;
        ll c; cin  >> c;
        g[to_idx(i, true, false)].push_back(edge{to_idx(i, false, false), c+1});
        g[to_idx(i, true, false)].push_back(edge{to_idx(i, false, true), c+1});

        g[to_idx(i, true, true)].push_back(edge{to_idx(i, false, false), c+1});
        g[to_idx(i, true, true)].push_back(edge{to_idx(i, false, true), c});
        for(int j = 0; j < k; j++){
            int s; cin >> s;
            g[s].push_back(edge{to_idx(i, true, s%2 == 0), s/2});
            g[to_idx(i, false, s%2 == 0)].push_back(edge{s, s/2});
        }
    }
    auto d = dijkstra(1, g);
    if(d[n] == INF){
        cout << -1 << endl;
    }else{
        cout << d[n] << endl;
    }
}
0