結果

問題 No.2820 Non-Preferred IUPAC Nomenclature
ユーザー ねしん
提出日時 2024-07-26 22:32:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,118 ms / 2,000 ms
コード長 540 bytes
コンパイル時間 429 ms
コンパイル使用メモリ 82,096 KB
実行使用メモリ 256,420 KB
最終ジャッジ日時 2024-07-26 22:33:06
合計ジャッジ時間 9,579 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys

sys.setrecursionlimit(500000)
ans=[]
check=set([1])
path=defaultdict(list)
def dfs(i):
  if i!=1:
    ans.append("(")
  for j in path[i]:
    if j not in check:
      check.add(j)
      dfs(j)
  if i!=1:
    ans.append("methyl)")
  else:
    ans.append("methane")
N=int(input())
for i in range(1,N+1):
  a=list(map(str,input().split()))
  for j in range(4):
    if a[j]!="H" and i<int(a[j]):     
      path[i].append(int(a[j]))
      path[int(a[j])].append(i)
dfs(1)
print("".join(ans))
    
0