結果

問題 No.2820 Non-Preferred IUPAC Nomenclature
ユーザー coindarw
提出日時 2024-07-26 22:09:30
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 719 bytes
コンパイル時間 2,789 ms
コンパイル使用メモリ 252,692 KB
実行使用メモリ 18,356 KB
最終ジャッジ日時 2024-07-26 22:09:40
合計ジャッジ時間 8,117 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 4; ++j) {
            string s;
            cin >> s;
            if (s == "H") {
                continue;
            }
            int x = stoi(s) - 1;
            G[i].push_back(x);
        }
    }
    vector<bool> seen(n, false);
    auto dfs = [&](auto dfs, int u) -> void {
        seen.at(u) = true;
        if (u) cout << "(";
        for (const auto &to : G.at(u)) {
            if (seen.at(to)) continue;
            dfs(dfs, to);
        }
        if (u) cout << "methyl)";
    };
    dfs(dfs, 0);
    cout << "methane" << endl;
}
0