結果

問題 No.2820 Non-Preferred IUPAC Nomenclature
ユーザー GOTKAKOGOTKAKO
提出日時 2024-07-26 21:37:22
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 2,850 ms
コンパイル使用メモリ 206,708 KB
実行使用メモリ 15,672 KB
最終ジャッジ日時 2024-07-26 21:37:31
合計ジャッジ時間 7,306 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    vector<vector<int>> Graph(N);
    for(int i=0; i<N; i++){
        for(int k=0; k<4; k++){
            string s; cin >> s;
            if(s == "H") continue;
            int u = stoi(s)-1;
            Graph.at(u).push_back(i);
            
        }
    }

    auto dfs = [&](auto dfs,int pos,int back) -> void {
        for(auto to : Graph.at(pos)){
            if(to == back) continue;
            cout << "(";
            dfs(dfs,to,pos);
            cout << ")";
        }
        if(back == -1) cout << "methane\n";
        else cout << "methyl";
    };
    dfs(dfs,0,-1);

}
0