結果
問題 | No.2820 Non-Preferred IUPAC Nomenclature |
ユーザー |
|
提出日時 | 2024-07-26 22:26:13 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 990 bytes |
コンパイル時間 | 661 ms |
コンパイル使用メモリ | 82,388 KB |
実行使用メモリ | 849,348 KB |
最終ジャッジ日時 | 2024-07-26 22:26:18 |
合計ジャッジ時間 | 4,315 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | MLE * 1 -- * 21 |
ソースコード
import sysinput = sys.stdin.readsys.setrecursionlimit(300000)def dfs(start):stk, p, vis = [(start, -1)], [-1] * (N + 1), [False] * (N + 1)vis[start] = Trueorder = []while stk:n, par = stk.pop()order.append((n, par))for nei in adj[n]:if not vis[nei]:vis[nei] = Truestk.append((nei, n))p[nei] = nnames = [""] * (N + 1)for n, par in reversed(order):if not adj[n]:names[n] = "methane"else:b = sorted(names[nei][:-3] for nei in adj[n] if nei != par)names[n] = "".join(f"({branch}yl)" for branch in b) + "methane"return names[start]d = input().split()N = int(d[0])adj = [[] for _ in range(N + 1)]idx = 1for i in range(1, N + 1):for _ in range(4):n = d[idx]idx += 1if n != 'H':n = int(n)if n != i:adj[i].append(n)print(dfs(1))