結果
問題 | No.2820 Non-Preferred IUPAC Nomenclature |
ユーザー |
![]() |
提出日時 | 2024-07-28 20:22:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 148 ms / 2,000 ms |
コード長 | 672 bytes |
コンパイル時間 | 2,048 ms |
コンパイル使用メモリ | 197,696 KB |
最終ジャッジ日時 | 2025-02-23 19:22:35 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } void dfs(int u, int pre, vector<vector<int>> &g, string &ans) { for (int v : g[u]) { if (v == pre) { continue; } ans += "("; dfs(v, u, g, ans); for (int i = 0; i < 3; i++) { ans.pop_back(); } ans += "yl)"; } ans += "methane"; } int main() { fast_io(); 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; } g[i].push_back(stoi(s) - 1); } } string ans = ""; dfs(0, -1, g, ans); cout << ans << endl; }