結果

問題 No.2820 Non-Preferred IUPAC Nomenclature
ユーザー 2000 Ekiben2000 Ekiben
提出日時 2024-07-26 22:31:24
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 921 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 82,160 KB
実行使用メモリ 849,172 KB
最終ジャッジ日時 2024-07-26 22:31:28
合計ジャッジ時間 4,010 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,604 KB
testcase_01 AC 37 ms
53,080 KB
testcase_02 AC 36 ms
53,748 KB
testcase_03 AC 38 ms
52,736 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.read
sys.setrecursionlimit(300000)
def dfs(start):
    stk = [(start, -1)]
    vis = [False] * (N + 1)
    vis[start] = True
    order = []

    while stk:
        n, par = stk.pop()
        order.append((n, par))
        for nei in adj[n]:
            if not vis[nei]:
                vis[nei] = True
                stk.append((nei, n))

    names = [""] * (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 = 1
for i in range(1, N + 1):
    for _ in range(4):
        n = d[idx]
        idx += 1
        if n != 'H':
            n = int(n)
            adj[i].append(n)
print(dfs(1))
0