結果

問題 No.1480 Many Complete Graphs
ユーザー chocoruskchocorusk
提出日時 2021-04-16 21:11:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 1,993 bytes
コンパイル時間 3,668 ms
コンパイル使用メモリ 192,896 KB
実行使用メモリ 34,716 KB
最終ジャッジ日時 2023-09-16 02:52:54
合計ジャッジ時間 9,499 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
26,560 KB
testcase_01 AC 9 ms
26,416 KB
testcase_02 AC 8 ms
26,480 KB
testcase_03 AC 8 ms
26,492 KB
testcase_04 AC 8 ms
26,404 KB
testcase_05 AC 8 ms
26,396 KB
testcase_06 AC 8 ms
26,404 KB
testcase_07 AC 8 ms
26,420 KB
testcase_08 AC 8 ms
26,704 KB
testcase_09 AC 8 ms
26,568 KB
testcase_10 AC 8 ms
26,532 KB
testcase_11 AC 9 ms
26,444 KB
testcase_12 AC 8 ms
26,484 KB
testcase_13 AC 28 ms
29,000 KB
testcase_14 AC 21 ms
28,248 KB
testcase_15 AC 41 ms
29,788 KB
testcase_16 AC 27 ms
28,440 KB
testcase_17 AC 27 ms
28,360 KB
testcase_18 AC 12 ms
27,304 KB
testcase_19 AC 28 ms
28,720 KB
testcase_20 AC 39 ms
29,180 KB
testcase_21 AC 30 ms
29,216 KB
testcase_22 AC 20 ms
28,000 KB
testcase_23 AC 59 ms
31,888 KB
testcase_24 AC 59 ms
31,336 KB
testcase_25 AC 77 ms
31,992 KB
testcase_26 AC 82 ms
32,544 KB
testcase_27 AC 64 ms
31,372 KB
testcase_28 AC 67 ms
33,196 KB
testcase_29 AC 70 ms
32,984 KB
testcase_30 AC 68 ms
32,692 KB
testcase_31 AC 67 ms
32,912 KB
testcase_32 AC 67 ms
32,988 KB
testcase_33 AC 66 ms
32,932 KB
testcase_34 AC 66 ms
33,084 KB
testcase_35 AC 65 ms
33,436 KB
testcase_36 AC 65 ms
33,156 KB
testcase_37 AC 65 ms
32,728 KB
testcase_38 AC 66 ms
33,152 KB
testcase_39 AC 64 ms
32,884 KB
testcase_40 AC 66 ms
32,796 KB
testcase_41 AC 65 ms
32,788 KB
testcase_42 AC 66 ms
33,144 KB
testcase_43 AC 67 ms
33,124 KB
testcase_44 AC 65 ms
32,600 KB
testcase_45 AC 67 ms
33,128 KB
testcase_46 AC 66 ms
32,748 KB
testcase_47 AC 125 ms
34,556 KB
testcase_48 AC 136 ms
34,624 KB
testcase_49 AC 129 ms
34,568 KB
testcase_50 AC 85 ms
34,424 KB
testcase_51 AC 125 ms
34,564 KB
testcase_52 AC 99 ms
33,720 KB
testcase_53 AC 100 ms
33,744 KB
testcase_54 AC 101 ms
33,728 KB
testcase_55 AC 99 ms
33,824 KB
testcase_56 AC 101 ms
33,672 KB
testcase_57 AC 86 ms
34,636 KB
testcase_58 AC 79 ms
34,716 KB
evil_aftercontest.txt AC 156 ms
43,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<ll, int> P;
using mint=modint998244353;
mint f[2000010], invf[2000010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i;
    invf[n]=f[n].inv();
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1);
}
mint comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]*invf[x-y];
}
vector<P> g[300030];
ll d[300030];
int main()
{
    int n, m;
    cin>>n>>m;
    
    for(int i=0; i<m; i++){
        int k; cin>>k;
        int c; cin>>c;
        for(int j=0; j<k; j++){
            int s; cin>>s;s--;
            if(s&1){
                g[s].push_back({n+i, s+c+1});
                g[n+i].push_back({s, s+c+1});
            }else{
                g[s].push_back({n+i+m, s+c+1});
                g[n+i+m].push_back({s, s+c+1});
            }
        }
        g[n+i+m].push_back({n+i, 1});
        g[n+i].push_back({n+i+m, 1});
    }
    const ll INF=1e18;
    
    fill(d, d+n+2*m, INF);
    d[0]=0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, 0});
    while(!que.empty()){
        auto p=que.top();que.pop();
        int x=p.second;
        if(d[x]<p.first) continue;
        for(auto q:g[x]){
            int y=q.first;
            if(d[y]>d[x]+q.second){
                d[y]=d[x]+q.second;
                que.push({d[y], y});
            }
        }
    }
    if(d[n-1]<INF/2) cout<<d[n-1]/2<<endl;
    else cout<<-1<<endl;
    return 0;
}
0