結果

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

ソースコード

diff #

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

int main() {
  int n; cin >> n;
  vector to(n, vector<int>());
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) {
      string s; cin >> s;
      if (s == "H") continue;
      int k = stoi(s);
      k--;
//       cerr << "edge " <<  i << " to " << k << endl;
      to[i].emplace_back(k);
    }
  }
  for (int i = 0; i < n; i++) {
//     cerr << to[i].size() << endl;
  }
  string ans;
  auto dfs = [&](auto&& self, int v, int p) -> void {
//     cerr << "v " << v << endl;
    for (auto u : to[v]) {
//       cerr << "u " << u << " " << p << endl;
      if (u == p) continue;
      ans += "(";
      self(self, u, v);
      ans.erase(ans.begin() + ans.size() - 3, ans.end());
      ans += "yl)";
    }
//     cerr << "v " << v << " " << ans << endl;
    ans += "methane";
  };
  dfs(dfs, 0, -1);
  cout << ans << endl;
}
0