結果

問題 No.2820 Non-Preferred IUPAC Nomenclature
ユーザー t98slider
提出日時 2024-07-27 19:37:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 637 bytes
コンパイル時間 2,290 ms
コンパイル使用メモリ 198,984 KB
最終ジャッジ日時 2025-02-23 19:18:35
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    string s;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 4; j++){
            cin >> s;
            if(s[0] != 'H'){
                int v = stoi(s) - 1;
                g[i].emplace_back(v);
            }
        }
    }
    auto dfs = [&](auto dfs, int v, int p) -> void {
        for(auto &&u : g[v]){
            if(u == p) continue;
            cout << '(';
            dfs(dfs, u, v);
            cout << ')';
        }
        cout << (p != -1 ? "methyl" : "methane\n");
    };
    dfs(dfs, 0, -1);
}
0