結果

問題 No.1480 Many Complete Graphs
ユーザー 👑 hos.lyrichos.lyric
提出日時 2021-08-14 12:27:52
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 2,846 bytes
コンパイル時間 1,312 ms
コンパイル使用メモリ 125,240 KB
実行使用メモリ 13,436 KB
最終ジャッジ日時 2023-09-04 13:39:49
合計ジャッジ時間 6,929 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 17 ms
7,248 KB
testcase_14 AC 13 ms
4,728 KB
testcase_15 AC 34 ms
6,304 KB
testcase_16 AC 21 ms
5,796 KB
testcase_17 AC 21 ms
5,352 KB
testcase_18 AC 6 ms
5,664 KB
testcase_19 AC 23 ms
5,240 KB
testcase_20 AC 31 ms
4,792 KB
testcase_21 AC 18 ms
6,524 KB
testcase_22 AC 11 ms
4,376 KB
testcase_23 AC 38 ms
10,124 KB
testcase_24 AC 45 ms
6,944 KB
testcase_25 AC 65 ms
6,912 KB
testcase_26 AC 74 ms
7,532 KB
testcase_27 AC 47 ms
6,964 KB
testcase_28 AC 74 ms
11,972 KB
testcase_29 AC 76 ms
10,584 KB
testcase_30 AC 76 ms
9,972 KB
testcase_31 AC 74 ms
9,896 KB
testcase_32 AC 76 ms
10,504 KB
testcase_33 AC 74 ms
9,848 KB
testcase_34 AC 75 ms
10,512 KB
testcase_35 AC 73 ms
9,924 KB
testcase_36 AC 74 ms
9,924 KB
testcase_37 AC 75 ms
9,848 KB
testcase_38 AC 75 ms
9,924 KB
testcase_39 AC 75 ms
9,872 KB
testcase_40 AC 75 ms
9,856 KB
testcase_41 AC 75 ms
11,836 KB
testcase_42 AC 75 ms
10,484 KB
testcase_43 AC 75 ms
11,984 KB
testcase_44 AC 74 ms
9,872 KB
testcase_45 AC 76 ms
10,480 KB
testcase_46 AC 74 ms
9,852 KB
testcase_47 AC 130 ms
12,744 KB
testcase_48 AC 134 ms
13,436 KB
testcase_49 AC 130 ms
12,216 KB
testcase_50 AC 65 ms
12,972 KB
testcase_51 AC 131 ms
12,628 KB
testcase_52 AC 98 ms
10,736 KB
testcase_53 AC 95 ms
9,280 KB
testcase_54 AC 96 ms
9,624 KB
testcase_55 AC 98 ms
11,036 KB
testcase_56 AC 102 ms
9,296 KB
testcase_57 AC 84 ms
13,192 KB
testcase_58 AC 83 ms
8,356 KB
evil_aftercontest.txt AC 165 ms
19,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum INF = 10L^^18;

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const M = readInt();
      auto K = new int[M];
      auto C = new long[M];
      auto S = new int[][M];
      foreach (m; 0 .. M) {
        K[m] = readInt();
        C[m] = readLong();
        S[m] = new int[K[m]];
        foreach (k; 0 .. K[m]) {
          S[m][k] = readInt() - 1;
        }
      }
      
      auto mss = new int[][N];
      foreach (m; 0 .. M) {
        foreach (u; S[m]) {
          mss[u] ~= m;
        }
      }
      
      alias Entry = Tuple!(long, "c", int, "u");
      BinaryHeap!(Array!Entry, "a.c > b.c") que;
      auto dist = new long[N + M * 2];
      dist[] = INF;
      que.insert(Entry(dist[0] = 0, 0));
      for (; !que.empty; ) {
        const c = que.front.c;
        const u = que.front.u;
        que.removeFront;
        if (dist[u] == c) {
          void update(int v, long cc) {
            if (chmin(dist[v], cc)) {
              que.insert(Entry(cc, v));
            }
          }
          if (u < N) {
            foreach (m; mss[u]) {
              if ((u + 1) % 2 == 0) {
                update(N + m * 2, c + (u + 1) / 2 + C[m]);
              }
              update(N + m * 2 + 1, c + (u + 1) / 2 + C[m] + 1);
            }
          } else {
            const m = (u - N) / 2;
            const s = (u - N) % 2;
            foreach (v; S[m]) {
              if ((s == 0) ? ((v + 1) % 2 == 0) : true) {
                update(v, c + (v + 1) / 2);
              }
            }
          }
        }
      }
      
      const ans = dist[N - 1];
      writeln((ans >= INF) ? -1 : ans);
    }
  } catch (EOFException e) {
  }
}
0