結果

問題 No.2820 Non-Preferred IUPAC Nomenclature
ユーザー Shirotsume
提出日時 2024-07-26 23:35:01
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,284 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 82,368 KB
実行使用メモリ 417,656 KB
最終ジャッジ日時 2024-07-26 23:35:06
合計ジャッジ時間 4,612 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other TLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 61 - 1
mod = 998244353
sys.setrecursionlimit(2 * 10 ** 5 + 1)
n = ii()
graph = [[] for _ in range(n)]
for i in range(n):
    a, b, c, d = input().split()
    if a != 'H':
        a = int(a) - 1
        graph[i].append(a)
    if b != 'H':
        b = int(b) - 1
        graph[i].append(b)
    if c != 'H':
        c = int(c) - 1
        graph[i].append(c)
    if d != 'H':
        d = int(d) - 1
        graph[i].append(d)
        
from collections import deque
def TreeDepth(s, graph):
    inf = 2 ** 61 - 1
    n = len(graph)
    depth = [inf] * n
    depth[s] = 0
    q = deque()
    q.append(s)
    while q:
        now = q.popleft()
        for to in graph[now]:
            if depth[to] == inf:
                depth[to] = depth[now] + 1
                q.append(to)
    return depth

TD = TreeDepth(0, graph)

def dfs(now):
    ans = []
    for to in graph[now]:
        if TD[to] > TD[now]:
            ans.append('(')
            ans.append(dfs(to)[:-3])
            ans.append('yl)')
    ans.append('methane')
    return ''.join(ans) 

print(dfs(0))   
0