結果

問題 No.812 Change of Class
ユーザー maspymaspy
提出日時 2020-02-07 10:43:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,353 ms / 4,000 ms
コード長 870 bytes
コンパイル時間 571 ms
コンパイル使用メモリ 10,756 KB
実行使用メモリ 78,432 KB
最終ジャッジ日時 2023-09-03 16:14:58
合計ジャッジ時間 39,544 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 362 ms
71,084 KB
testcase_01 AC 240 ms
46,916 KB
testcase_02 AC 283 ms
58,088 KB
testcase_03 AC 387 ms
76,092 KB
testcase_04 AC 356 ms
72,132 KB
testcase_05 AC 1,353 ms
73,884 KB
testcase_06 AC 1,000 ms
65,884 KB
testcase_07 AC 223 ms
53,984 KB
testcase_08 AC 211 ms
46,744 KB
testcase_09 AC 1,225 ms
78,368 KB
testcase_10 AC 1,322 ms
78,432 KB
testcase_11 AC 248 ms
74,492 KB
testcase_12 AC 856 ms
77,156 KB
testcase_13 AC 205 ms
42,784 KB
testcase_14 AC 203 ms
43,012 KB
testcase_15 AC 860 ms
65,620 KB
testcase_16 AC 243 ms
44,364 KB
testcase_17 AC 859 ms
67,512 KB
testcase_18 AC 627 ms
60,948 KB
testcase_19 AC 684 ms
64,040 KB
testcase_20 AC 1,300 ms
77,636 KB
testcase_21 AC 576 ms
60,092 KB
testcase_22 AC 367 ms
50,956 KB
testcase_23 AC 228 ms
44,088 KB
testcase_24 AC 245 ms
44,884 KB
testcase_25 AC 342 ms
49,312 KB
testcase_26 AC 1,100 ms
72,096 KB
testcase_27 AC 904 ms
68,332 KB
testcase_28 AC 643 ms
63,668 KB
testcase_29 AC 296 ms
46,932 KB
testcase_30 AC 832 ms
66,848 KB
testcase_31 AC 711 ms
63,144 KB
testcase_32 AC 408 ms
52,904 KB
testcase_33 AC 876 ms
70,012 KB
testcase_34 AC 242 ms
44,876 KB
testcase_35 AC 329 ms
49,440 KB
testcase_36 AC 254 ms
44,960 KB
testcase_37 AC 546 ms
54,504 KB
testcase_38 AC 232 ms
57,076 KB
testcase_39 AC 523 ms
54,616 KB
testcase_40 AC 266 ms
46,816 KB
testcase_41 AC 230 ms
55,420 KB
testcase_42 AC 968 ms
66,200 KB
testcase_43 AC 270 ms
63,376 KB
testcase_44 AC 718 ms
59,468 KB
testcase_45 AC 252 ms
44,980 KB
testcase_46 AC 262 ms
62,300 KB
testcase_47 AC 751 ms
59,520 KB
testcase_48 AC 759 ms
64,920 KB
testcase_49 AC 339 ms
48,344 KB
testcase_50 AC 217 ms
43,668 KB
testcase_51 AC 322 ms
51,472 KB
testcase_52 AC 433 ms
63,260 KB
testcase_53 AC 299 ms
46,192 KB
testcase_54 AC 280 ms
46,012 KB
testcase_55 AC 416 ms
65,416 KB
testcase_56 AC 460 ms
69,672 KB
testcase_57 AC 476 ms
71,408 KB
testcase_58 AC 347 ms
57,492 KB
testcase_59 AC 515 ms
75,388 KB
testcase_60 AC 201 ms
43,368 KB
testcase_61 AC 209 ms
43,328 KB
testcase_62 AC 206 ms
43,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
from scipy.sparse.csgraph import connected_components, dijkstra
from scipy.sparse import csr_matrix

data = np.fromstring(read(), np.int64, sep=' ')

N, M = data[:2]
UV = data[2:2+M+M]
U = UV[::2]
V = UV[1::2]
Q = data[2+M+M]
A = data[2+M+M+1:]

graph = csr_matrix((np.ones_like(U), (U, V)), (N+1, N+1))

_, comp = connected_components(graph)
comp_size = np.bincount(comp)

dist = dijkstra(graph, directed=False, indices=A)

dist[dist == np.inf] = 0
dist = dist.max(axis=1).astype(int)

sizes = comp_size[comp[A]]

def gen_answers():
    for s, d in zip(sizes, dist):
        if d <= 1:
            day = 0
        else:
            day = int(d-1).bit_length()
        yield '{} {}'.format(s - 1, day)

print('\n'.join(gen_answers()))
0