結果

問題 No.1480 Many Complete Graphs
ユーザー 👑 NachiaNachia
提出日時 2021-04-16 20:46:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,045 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 86,252 KB
実行使用メモリ 13,232 KB
最終ジャッジ日時 2023-09-16 02:48:18
合計ジャッジ時間 5,041 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 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,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 13 ms
7,236 KB
testcase_14 AC 10 ms
5,752 KB
testcase_15 AC 24 ms
8,424 KB
testcase_16 AC 13 ms
7,264 KB
testcase_17 AC 13 ms
6,836 KB
testcase_18 AC 5 ms
5,716 KB
testcase_19 AC 14 ms
6,760 KB
testcase_20 AC 19 ms
7,084 KB
testcase_21 AC 14 ms
7,000 KB
testcase_22 AC 8 ms
5,144 KB
testcase_23 AC 32 ms
10,788 KB
testcase_24 AC 31 ms
8,656 KB
testcase_25 AC 42 ms
10,584 KB
testcase_26 AC 48 ms
11,672 KB
testcase_27 AC 31 ms
8,880 KB
testcase_28 AC 40 ms
12,216 KB
testcase_29 AC 43 ms
12,208 KB
testcase_30 AC 39 ms
11,964 KB
testcase_31 AC 39 ms
11,948 KB
testcase_32 AC 39 ms
12,124 KB
testcase_33 AC 38 ms
12,028 KB
testcase_34 AC 39 ms
12,172 KB
testcase_35 AC 40 ms
12,100 KB
testcase_36 AC 40 ms
12,288 KB
testcase_37 AC 38 ms
11,948 KB
testcase_38 AC 39 ms
12,288 KB
testcase_39 AC 39 ms
12,044 KB
testcase_40 AC 37 ms
11,952 KB
testcase_41 AC 40 ms
11,892 KB
testcase_42 AC 41 ms
12,208 KB
testcase_43 AC 40 ms
12,244 KB
testcase_44 AC 41 ms
11,976 KB
testcase_45 AC 41 ms
12,184 KB
testcase_46 AC 38 ms
11,896 KB
testcase_47 AC 71 ms
12,540 KB
testcase_48 AC 69 ms
12,500 KB
testcase_49 AC 65 ms
12,764 KB
testcase_50 AC 40 ms
12,228 KB
testcase_51 AC 69 ms
12,556 KB
testcase_52 AC 52 ms
12,952 KB
testcase_53 AC 50 ms
13,064 KB
testcase_54 AC 54 ms
12,976 KB
testcase_55 AC 53 ms
13,232 KB
testcase_56 AC 58 ms
12,968 KB
testcase_57 AC 38 ms
10,984 KB
testcase_58 AC 38 ms
12,116 KB
evil_aftercontest.txt AC 73 ms
21,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
using ll=long long;
using ull=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

template<class E> using nega_queue = priority_queue<E,vector<E>,greater<E>>;

const ll INF = 1001001001001001001;

struct Edge{ int to; ll d; };

int N,M;
vector<vector<Edge>> E;
vector<ll> D;

int main(){
  scanf("%d%d",&N,&M);
  E.resize(N+M);
  rep(i,M){
    int k,c; scanf("%d%d",&k,&c);
    rep(kk,k){
      int s; scanf("%d",&s);
      E[s-1].push_back({N+i,s+c});
      E[N+i].push_back({s-1,s+c});
    }
  }

  D.assign(N+M,INF);
  nega_queue<pair<ll,int>> Q;
  D[0]=0; Q.push({0,0});
  while(Q.size()){
    ll d = Q.top().first;
    int p = Q.top().second; Q.pop();
    if(D[p]!=d) continue;
    for(auto e : E[p]){
      ll nxd = D[p] + e.d;
      if(e.to<N) if(nxd%2==1) nxd++;
      if(D[e.to]<=nxd) continue;
      D[e.to] = nxd; Q.push({nxd,e.to});
    }
  }


  if(D[N-1] == INF) printf("-1\n");
  else printf("%lld\n",D[N-1]/2);
  return 0;
}
0