結果
問題 |
No.2820 Non-Preferred IUPAC Nomenclature
|
ユーザー |
|
提出日時 | 2024-07-26 22:37:57 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 969 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 82,536 KB |
実行使用メモリ | 131,576 KB |
最終ジャッジ日時 | 2024-07-26 22:38:02 |
合計ジャッジ時間 | 3,340 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 4 |
other | RE * 22 |
ソースコード
import sys from collections import deque input = sys.stdin.read sys.setrecursionlimit(300000) def bfs(start): queue = deque([(start, -1)]) vis = [False] * (N + 1) vis[start] = True order = [] while queue: n, par = queue.popleft() order.append((n, par)) for nei in adj[n]: if not vis[nei]: vis[nei] = True queue.append((nei, n)) names = [""] * (N + 1) for n, par in reversed(order): if not adj[n]: names[n] = "methane" else: branches = sorted(names[nei][:-3] for nei in adj[n] if nei != par) names[n] = "".join(f"({branch}yl)" for branch in branches) + "methane" return names[start] d = input().split() N = int(data[0]) adj = [[] for _ in range(N + 1)] idx = 1 for i in range(1, N + 1): for _ in range(4): n = d[idx] idx += 1 if n != 'H': adj[i].append(int(n)) print(bfs(1))