結果
問題 | No.812 Change of Class |
ユーザー |
![]() |
提出日時 | 2020-08-27 18:46:57 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,242 bytes |
コンパイル時間 | 170 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 128,000 KB |
最終ジャッジ日時 | 2024-11-07 23:29:16 |
合計ジャッジ時間 | 23,323 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 35 WA * 25 |
ソースコード
import sys; input = sys.stdin.buffer.readlinesys.setrecursionlimit(10**7)from collections import defaultdictfrom collections import dequecon = 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.graphself.Q = deque(); self.Q.append(s)self.dist = [INF] * N; self.dist[s] = 0while self.Q:v = self.Q.popleft()for i in self.g[v]:if self.dist[i] == INF:self.dist[i] = self.dist[v] + 1self.Q.append(i)#処理内容def main():N, M = getlist()G = Graph()for i in range(M):a, b = getlist()a -= 1; b -= 1G.add_edge(a, b)G.add_edge(b, a)Q = int(input())for _ in range(Q):A = int(input())A -= 1BF = BFS(G, A, N)cnt = 0MAX = 0for i in range(N):d = BF.dist[i]if d != INF:cnt += 1MAX = max(MAX, d)cnt -= 1if MAX == 0:day = 0else:for i in range(1, 50):if 2 ** i >= MAX:day = ibreakprint(cnt, day)if __name__ == '__main__':main()