結果
問題 | No.2325 Skill Tree |
ユーザー |
![]() |
提出日時 | 2023-05-28 14:14:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 596 ms / 3,000 ms |
コード長 | 1,728 bytes |
コンパイル時間 | 1,943 ms |
コンパイル使用メモリ | 180,984 KB |
実行使用メモリ | 14,976 KB |
最終ジャッジ日時 | 2024-12-27 00:10:22 |
合計ジャッジ時間 | 21,718 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h>//#include <atcoder/all>using namespace std;//using namespace atcoder;typedef long long ll;//typedef modint1000000007 mint;const int MOD = 1000000007;#define all(x) x.begin(), x.end()#define rep(i, n) for (int i = 0; i < (int)(n); i++)const int inf = 1 << 30;const ll INF = 1LL << 60;const int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};const int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }int main(){int n;cin >> n;vector<int> l(n), a(n);rep(i, n - 1) cin >> l[i + 1] >> a[i + 1];vector<vector<int>> g(n);rep(i, n - 1) g[a[i + 1] - 1].push_back(i + 1);vector<bool> seen(n, false);vector<int> level(n, inf);seen[0] = true;level[0] = 0;queue<int> que;que.push(0);while(!que.empty()){int v = que.front();que.pop();for(auto u : g[v]){if(!seen[u]){seen[u] = true;level[u] = max(l[u], level[v]);que.push(u);}}}vector<int> level2 = level;sort(all(level2));//rep(i, n) cout << level2[i] << endl;int q;cin >> q;while(q--){int num, x, y;cin >> num;if(num == 1){cin >> x;auto it = upper_bound(all(level2), x);cout << it - level2.begin() << endl;}if(num == 2){cin >> y;if(level[y - 1] == inf) cout << -1 << endl;else cout << level[y - 1] << endl;}}return 0;}