結果
問題 | No.812 Change of Class |
ユーザー | maspy |
提出日時 | 2020-02-07 10:43:29 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,728 ms / 4,000 ms |
コード長 | 870 bytes |
コンパイル時間 | 208 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 89,004 KB |
最終ジャッジ日時 | 2024-06-12 21:55:01 |
合計ジャッジ時間 | 75,508 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
外部呼び出し有り |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 975 ms
81,560 KB |
testcase_01 | AC | 865 ms
57,260 KB |
testcase_02 | AC | 935 ms
68,336 KB |
testcase_03 | AC | 1,014 ms
86,288 KB |
testcase_04 | AC | 993 ms
82,284 KB |
testcase_05 | AC | 1,728 ms
84,056 KB |
testcase_06 | AC | 1,532 ms
76,052 KB |
testcase_07 | AC | 857 ms
64,648 KB |
testcase_08 | AC | 908 ms
57,684 KB |
testcase_09 | AC | 1,591 ms
88,808 KB |
testcase_10 | AC | 1,680 ms
89,004 KB |
testcase_11 | AC | 886 ms
85,176 KB |
testcase_12 | AC | 1,438 ms
87,604 KB |
testcase_13 | AC | 846 ms
54,616 KB |
testcase_14 | AC | 850 ms
54,628 KB |
testcase_15 | AC | 1,395 ms
76,100 KB |
testcase_16 | AC | 880 ms
54,832 KB |
testcase_17 | AC | 1,317 ms
77,788 KB |
testcase_18 | AC | 1,199 ms
71,744 KB |
testcase_19 | AC | 1,272 ms
74,056 KB |
testcase_20 | AC | 1,659 ms
88,252 KB |
testcase_21 | AC | 1,180 ms
70,608 KB |
testcase_22 | AC | 1,010 ms
60,824 KB |
testcase_23 | AC | 865 ms
54,844 KB |
testcase_24 | AC | 899 ms
55,520 KB |
testcase_25 | AC | 969 ms
59,044 KB |
testcase_26 | AC | 1,553 ms
82,060 KB |
testcase_27 | AC | 1,471 ms
78,728 KB |
testcase_28 | AC | 1,273 ms
74,308 KB |
testcase_29 | AC | 950 ms
57,268 KB |
testcase_30 | AC | 1,382 ms
77,628 KB |
testcase_31 | AC | 1,335 ms
73,260 KB |
testcase_32 | AC | 1,044 ms
63,456 KB |
testcase_33 | AC | 1,372 ms
80,404 KB |
testcase_34 | AC | 871 ms
55,268 KB |
testcase_35 | AC | 991 ms
59,120 KB |
testcase_36 | AC | 919 ms
54,872 KB |
testcase_37 | AC | 1,145 ms
64,804 KB |
testcase_38 | AC | 891 ms
67,496 KB |
testcase_39 | AC | 1,138 ms
64,860 KB |
testcase_40 | AC | 907 ms
57,252 KB |
testcase_41 | AC | 856 ms
65,836 KB |
testcase_42 | AC | 1,477 ms
76,560 KB |
testcase_43 | AC | 890 ms
73,336 KB |
testcase_44 | AC | 1,257 ms
69,868 KB |
testcase_45 | AC | 884 ms
55,392 KB |
testcase_46 | AC | 888 ms
72,776 KB |
testcase_47 | AC | 1,238 ms
69,908 KB |
testcase_48 | AC | 1,241 ms
75,288 KB |
testcase_49 | AC | 987 ms
58,516 KB |
testcase_50 | AC | 862 ms
54,620 KB |
testcase_51 | AC | 953 ms
61,740 KB |
testcase_52 | AC | 1,013 ms
74,028 KB |
testcase_53 | AC | 905 ms
56,668 KB |
testcase_54 | AC | 911 ms
56,420 KB |
testcase_55 | AC | 1,038 ms
76,472 KB |
testcase_56 | AC | 1,075 ms
80,236 KB |
testcase_57 | AC | 1,078 ms
82,016 KB |
testcase_58 | AC | 966 ms
67,972 KB |
testcase_59 | AC | 1,095 ms
85,904 KB |
testcase_60 | AC | 845 ms
54,628 KB |
testcase_61 | AC | 852 ms
54,340 KB |
testcase_62 | AC | 853 ms
54,612 KB |
ソースコード
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()))