結果

問題 No.812 Change of Class
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-04-19 20:27:20
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 398 ms / 4,000 ms
コード長 2,370 bytes
コンパイル時間 766 ms
コンパイル使用メモリ 109,092 KB
実行使用メモリ 28,684 KB
最終ジャッジ日時 2023-09-04 00:39:46
合計ジャッジ時間 13,153 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 272 ms
14,504 KB
testcase_01 AC 43 ms
4,376 KB
testcase_02 AC 148 ms
14,168 KB
testcase_03 AC 324 ms
14,792 KB
testcase_04 AC 285 ms
14,904 KB
testcase_05 AC 398 ms
14,780 KB
testcase_06 AC 325 ms
13,980 KB
testcase_07 AC 6 ms
6,692 KB
testcase_08 AC 3 ms
5,464 KB
testcase_09 AC 369 ms
18,040 KB
testcase_10 AC 385 ms
17,804 KB
testcase_11 AC 28 ms
14,652 KB
testcase_12 AC 250 ms
19,292 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 262 ms
14,736 KB
testcase_16 AC 19 ms
4,380 KB
testcase_17 AC 238 ms
15,032 KB
testcase_18 AC 182 ms
14,412 KB
testcase_19 AC 205 ms
14,800 KB
testcase_20 AC 394 ms
17,344 KB
testcase_21 AC 172 ms
14,200 KB
testcase_22 AC 85 ms
4,680 KB
testcase_23 AC 16 ms
4,380 KB
testcase_24 AC 23 ms
4,384 KB
testcase_25 AC 67 ms
12,952 KB
testcase_26 AC 322 ms
16,440 KB
testcase_27 AC 282 ms
14,840 KB
testcase_28 AC 198 ms
14,516 KB
testcase_29 AC 50 ms
4,380 KB
testcase_30 AC 252 ms
15,116 KB
testcase_31 AC 220 ms
14,696 KB
testcase_32 AC 100 ms
13,724 KB
testcase_33 AC 264 ms
17,768 KB
testcase_34 AC 21 ms
4,380 KB
testcase_35 AC 59 ms
4,404 KB
testcase_36 AC 25 ms
4,380 KB
testcase_37 AC 145 ms
14,188 KB
testcase_38 AC 11 ms
7,516 KB
testcase_39 AC 147 ms
13,980 KB
testcase_40 AC 37 ms
4,380 KB
testcase_41 AC 9 ms
7,212 KB
testcase_42 AC 308 ms
14,664 KB
testcase_43 AC 53 ms
9,128 KB
testcase_44 AC 212 ms
13,520 KB
testcase_45 AC 26 ms
4,380 KB
testcase_46 AC 48 ms
8,584 KB
testcase_47 AC 210 ms
13,588 KB
testcase_48 AC 219 ms
14,456 KB
testcase_49 AC 67 ms
4,376 KB
testcase_50 AC 5 ms
4,380 KB
testcase_51 AC 65 ms
4,700 KB
testcase_52 AC 118 ms
15,200 KB
testcase_53 AC 44 ms
4,384 KB
testcase_54 AC 37 ms
4,380 KB
testcase_55 AC 234 ms
14,004 KB
testcase_56 AC 301 ms
14,404 KB
testcase_57 AC 312 ms
14,260 KB
testcase_58 AC 150 ms
14,876 KB
testcase_59 AC 361 ms
28,684 KB
testcase_60 AC 1 ms
4,380 KB
testcase_61 AC 1 ms
4,376 KB
testcase_62 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.range, 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)); }


int N, M;
int[] U, V;
int Q;
int[] A;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      M = readInt();
      U = new int[M];
      V = new int[M];
      foreach (i; 0 .. M) {
        U[i] = readInt() - 1;
        V[i] = readInt() - 1;
      }
      Q = readInt();
      A = new int[Q];
      foreach (q; 0 .. Q) {
        A[q] = readInt() - 1;
      }
      
      auto graph = new int[][N];
      foreach (i; 0 .. M) {
        graph[U[i]] ~= V[i];
        graph[V[i]] ~= U[i];
      }
      foreach (q; 0 .. Q) {
        DList!int que;
        auto dist = new int[N];
        dist[] = -1;
        dist[A[q]] = 0;
        que.insertBack(A[q]);
        for (; !que.empty; ) {
          const u = que.front;
          que.removeFront;
          foreach (v; graph[u]) {
            if (dist[v] == -1) {
              dist[v] = dist[u] + 1;
              que.insertBack(v);
            }
          }
        }
        int cnt, mx;
        foreach (u; 0 .. N) {
          if (dist[u] != -1) {
            ++cnt;
            chmax(mx, dist[u]);
          }
        }
        int ans;
        for (ans = 0; (1 << ans) < mx; ++ans) {}
        writeln(cnt - 1, " ", ans);
      }
    }
  } catch (EOFException e) {
  }
}
0