結果

問題 No.812 Change of Class
ユーザー 双六双六
提出日時 2020-08-27 18:48:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 842 ms / 4,000 ms
コード長 1,239 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 127,360 KB
最終ジャッジ日時 2024-04-25 12:06:56
合計ジャッジ時間 20,383 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 285 ms
103,552 KB
testcase_01 AC 111 ms
79,104 KB
testcase_02 AC 199 ms
90,112 KB
testcase_03 AC 321 ms
108,288 KB
testcase_04 AC 294 ms
102,016 KB
testcase_05 AC 842 ms
103,808 KB
testcase_06 AC 577 ms
98,176 KB
testcase_07 AC 67 ms
77,568 KB
testcase_08 AC 53 ms
66,560 KB
testcase_09 AC 787 ms
110,208 KB
testcase_10 AC 772 ms
108,416 KB
testcase_11 AC 138 ms
127,360 KB
testcase_12 AC 472 ms
110,080 KB
testcase_13 AC 45 ms
54,016 KB
testcase_14 AC 46 ms
54,400 KB
testcase_15 AC 515 ms
95,744 KB
testcase_16 AC 134 ms
77,568 KB
testcase_17 AC 507 ms
98,688 KB
testcase_18 AC 365 ms
93,184 KB
testcase_19 AC 415 ms
95,488 KB
testcase_20 AC 818 ms
110,464 KB
testcase_21 AC 361 ms
91,136 KB
testcase_22 AC 217 ms
88,064 KB
testcase_23 AC 106 ms
77,312 KB
testcase_24 AC 114 ms
77,824 KB
testcase_25 AC 172 ms
85,760 KB
testcase_26 AC 661 ms
102,528 KB
testcase_27 AC 591 ms
99,328 KB
testcase_28 AC 393 ms
96,640 KB
testcase_29 AC 151 ms
78,976 KB
testcase_30 AC 514 ms
98,048 KB
testcase_31 AC 434 ms
94,592 KB
testcase_32 AC 225 ms
87,936 KB
testcase_33 AC 617 ms
104,064 KB
testcase_34 AC 114 ms
77,696 KB
testcase_35 AC 160 ms
85,504 KB
testcase_36 AC 107 ms
77,952 KB
testcase_37 AC 286 ms
88,448 KB
testcase_38 AC 94 ms
94,336 KB
testcase_39 AC 265 ms
90,112 KB
testcase_40 AC 139 ms
78,848 KB
testcase_41 AC 87 ms
87,936 KB
testcase_42 AC 599 ms
98,688 KB
testcase_43 AC 171 ms
110,720 KB
testcase_44 AC 349 ms
94,592 KB
testcase_45 AC 117 ms
77,824 KB
testcase_46 AC 157 ms
109,568 KB
testcase_47 AC 341 ms
93,952 KB
testcase_48 AC 403 ms
95,360 KB
testcase_49 AC 155 ms
80,128 KB
testcase_50 AC 70 ms
69,632 KB
testcase_51 AC 168 ms
87,808 KB
testcase_52 AC 248 ms
94,848 KB
testcase_53 AC 135 ms
78,720 KB
testcase_54 AC 118 ms
78,336 KB
testcase_55 AC 274 ms
102,272 KB
testcase_56 AC 269 ms
109,440 KB
testcase_57 AC 289 ms
111,360 KB
testcase_58 AC 189 ms
92,032 KB
testcase_59 AC 320 ms
115,840 KB
testcase_60 AC 43 ms
54,272 KB
testcase_61 AC 45 ms
53,888 KB
testcase_62 AC 43 ms
53,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
from collections import deque
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

class BFS(object):
	def __init__(self, graph, s, N):
		self.g = graph.graph
		self.Q = deque(); self.Q.append(s)
		self.dist = [INF] * N; self.dist[s] = 0
		while self.Q:
			v = self.Q.popleft()
			for i in self.g[v]:
				if self.dist[i] == INF:
					self.dist[i] = self.dist[v] + 1
					self.Q.append(i)

#処理内容
def main():
	N, M = getlist()
	G = Graph()
	for i in range(M):
		a, b = getlist()
		a -= 1; b -= 1
		G.add_edge(a, b)
		G.add_edge(b, a)

	Q = int(input())
	for _ in range(Q):
		A = int(input())
		A -= 1

		BF = BFS(G, A, N)
		cnt = 0
		MAX = 0
		for i in range(N):
			d = BF.dist[i] 
			if d != INF:
				cnt += 1
				MAX = max(MAX, d)
		cnt -= 1

		if MAX == 0:
			day = 0
		else:
			for i in range(50):
				if 2 ** i >= MAX:
					day = i
					break

		print(cnt, day)
	

if __name__ == '__main__':
	main()
0