結果
問題 | No.2325 Skill Tree |
ユーザー |
|
提出日時 | 2023-05-28 15:09:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,182 bytes |
コンパイル時間 | 2,402 ms |
コンパイル使用メモリ | 207,220 KB |
最終ジャッジ日時 | 2025-02-13 12:37:21 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 17 WA * 19 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;int main() {int n;cin >> n;vector<vector<int>> g(n);vector<int> levels(n);for (int i = 1; i < n; i++) {int l, a;cin >> l >> a;--a;levels[i] = l;g[a].push_back(i);}vector<int> type2(n, -1);queue<int> que;que.push(0);type2[0] = 0;while (!que.empty()) {auto cur = que.front();que.pop();for (auto to : g[cur]) {if (auto greaterLevel = max(levels[to], levels[cur]); type2[to] < greaterLevel) {type2[to] = greaterLevel;}que.push(to);}}auto type1 = type2;int exclude = 0;for (int i = 0; i < n; i++) {if (type1[i] == -1) {exclude++;}}sort(type1.begin(), type1.end());int q;cin >> q;while (q--) {int type, x;cin >> type >> x;if (type == 1) {cout << (upper_bound(type1.begin(), type1.end(), x) - type1.begin()) - exclude << endl;}else {cout << type2[x - 1] << endl;}}}