結果
問題 | No.2325 Skill Tree |
ユーザー |
|
提出日時 | 2023-05-28 15:25:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,669 bytes |
コンパイル時間 | 2,062 ms |
コンパイル使用メモリ | 201,612 KB |
最終ジャッジ日時 | 2025-02-13 13:16:01 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 8 TLE * 28 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) using ll = unsigned long long; using Graph = vector<vector<int>>; int main() { int n; cin >> n; vector<pair<int, int>> waza(n); waza.at(0) = make_pair(0, 0); for (int i = 1; i < n; i++) { int l, a; cin >> l >> a; l--; a--; waza.at(i) = make_pair(l, a); } int Q; cin >> Q; rep(i, Q) { int q, x; cin >> q >> x; x--; if (q == 1) { int ans = 1; set<int> oboe; oboe.insert(0); while (1) { for (int j = 1; j < n; j++) { if (waza.at(j).first <= x && oboe.count(waza.at(j).second)) { oboe.insert(j); } } if (oboe.size() == ans) { cout << ans << endl; break; } ans = oboe.size(); } } else if (q == 2) { int ans = -1; set<int> used_x; while (1) { ans = max(waza.at(x).first, ans); x = waza.at(x).second; if (x == 0) { cout << ans + 1 << endl; break; } if (used_x.count(x)) { cout << -1 << endl; break; } used_x.insert(x); } } } }