結果

問題 No.1480 Many Complete Graphs
ユーザー tnakao0123tnakao0123
提出日時 2021-04-17 18:32:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,840 bytes
コンパイル時間 952 ms
コンパイル使用メモリ 99,840 KB
実行使用メモリ 17,096 KB
最終ジャッジ日時 2023-09-17 03:55:25
合計ジャッジ時間 6,103 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,872 KB
testcase_01 AC 4 ms
10,892 KB
testcase_02 AC 4 ms
10,828 KB
testcase_03 AC 5 ms
10,948 KB
testcase_04 AC 4 ms
10,888 KB
testcase_05 AC 5 ms
10,796 KB
testcase_06 AC 4 ms
10,888 KB
testcase_07 AC 4 ms
10,900 KB
testcase_08 AC 4 ms
10,964 KB
testcase_09 AC 5 ms
11,076 KB
testcase_10 AC 4 ms
10,968 KB
testcase_11 AC 4 ms
10,980 KB
testcase_12 AC 5 ms
11,168 KB
testcase_13 AC 14 ms
12,808 KB
testcase_14 AC 11 ms
12,240 KB
testcase_15 AC 22 ms
13,344 KB
testcase_16 AC 15 ms
12,584 KB
testcase_17 AC 15 ms
12,576 KB
testcase_18 AC 6 ms
11,632 KB
testcase_19 AC 14 ms
12,468 KB
testcase_20 AC 21 ms
12,736 KB
testcase_21 AC 16 ms
12,868 KB
testcase_22 AC 11 ms
11,864 KB
testcase_23 AC 29 ms
14,848 KB
testcase_24 AC 29 ms
13,792 KB
testcase_25 AC 40 ms
14,492 KB
testcase_26 AC 39 ms
15,400 KB
testcase_27 AC 30 ms
13,928 KB
testcase_28 AC 32 ms
15,800 KB
testcase_29 AC 32 ms
15,868 KB
testcase_30 AC 33 ms
15,868 KB
testcase_31 AC 33 ms
15,864 KB
testcase_32 AC 34 ms
16,196 KB
testcase_33 AC 33 ms
16,088 KB
testcase_34 AC 32 ms
15,800 KB
testcase_35 AC 42 ms
16,288 KB
testcase_36 AC 40 ms
16,192 KB
testcase_37 AC 36 ms
15,752 KB
testcase_38 AC 41 ms
16,508 KB
testcase_39 AC 41 ms
15,920 KB
testcase_40 AC 38 ms
15,960 KB
testcase_41 AC 37 ms
15,968 KB
testcase_42 AC 41 ms
16,328 KB
testcase_43 AC 41 ms
16,276 KB
testcase_44 AC 41 ms
15,892 KB
testcase_45 AC 43 ms
16,164 KB
testcase_46 AC 43 ms
15,924 KB
testcase_47 AC 71 ms
17,036 KB
testcase_48 AC 63 ms
16,980 KB
testcase_49 AC 68 ms
17,096 KB
testcase_50 AC 44 ms
16,992 KB
testcase_51 AC 71 ms
16,984 KB
testcase_52 AC 53 ms
16,820 KB
testcase_53 AC 57 ms
16,500 KB
testcase_54 AC 59 ms
16,676 KB
testcase_55 AC 60 ms
16,616 KB
testcase_56 AC 55 ms
16,684 KB
testcase_57 AC 45 ms
16,984 KB
testcase_58 AC 42 ms
16,856 KB
evil_aftercontest.txt AC 80 ms
23,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1480.cc:  No.1480 Many Complete Graphs - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 100000;
const int MAX_GN = MAX_N + MAX_M * 2;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

vpii nbrs[MAX_GN];
ll ds[MAX_GN];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < m; i++) {
    int t0 = n + i * 2, t1 = t0 + 1;
    nbrs[t0].push_back(pii(t1, 1));
    nbrs[t1].push_back(pii(t0, 1));

    int ki, ci;
    scanf("%d%d", &ki, &ci);
    for (int j = 0; j < ki; j++) {
      int sj;
      scanf("%d", &sj);
      sj--;
      int tj = (sj & 1) ? t1 : t0;
      int wj = sj + 1 + ci;
      nbrs[sj].push_back(pii(tj, wj));
      nbrs[tj].push_back(pii(sj, wj));
    }
  }

  int gn = n + m * 2, st = 0, gl = n - 1;
  fill(ds, ds + gn, LINF);
  ds[st] = 0;

  priority_queue<pli> q;
  q.push(pli(0, st));

  while (! q.empty()) {
    pli u = q.top(); q.pop();
    ll ud = -u.first;
    int ui = u.second;
    if (ds[ui] != ud) continue;
    if (ui == gl) break;

    vpii &nbru = nbrs[ui];
    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int vi = vit->first;
      ll vd = ud + vit->second;
      if (ds[vi] > vd) {
	ds[vi] = vd;
	q.push(pli(-vd, vi));
      }
    }
  }

  printf("%lld\n", (ds[gl] >= LINF) ? -1 : ds[gl] / 2);
  return 0;
}
0