結果
問題 | No.2325 Skill Tree |
ユーザー |
|
提出日時 | 2023-05-28 14:37:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 141 ms / 3,000 ms |
コード長 | 1,384 bytes |
コンパイル時間 | 2,459 ms |
コンパイル使用メモリ | 226,912 KB |
最終ジャッジ日時 | 2025-02-13 11:49:16 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#pragma GCC optimize("Ofast")#include <bits/stdc++.h>using namespace std;typedef long long int ll;typedef unsigned long long int ull;mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());ll myRand(ll B) {return (ull)rng() % B;}inline double time() {return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;}int main(){cin.tie(nullptr);ios::sync_with_stdio(false);int n; cin >> n;vector<int> ok(n,-1);ok[0] = 0;vector<vector<pair<int,int>>> g(n);for (int i = 1; i < n; ++i) {int l,a; cin >> l >> a;a--;g[a].push_back({i,l});}{queue<int> q;q.push(0);while (q.size()) {int s = q.front(); q.pop();for (auto p : g[s]) {ok[p.first] = max(p.second, ok[s]);q.push(p.first);}}}vector<int> v;for (int i = 0; i < n; ++i) {if (ok[i] != -1) {v.push_back(ok[i]);}}sort(v.begin(), v.end());int q; cin >> q;while (q--) {int t,x; cin >> t >> x;if (t == 1) {cout << lower_bound(v.begin(), v.end(), x+1) - v.begin() << "\n";}else {cout << ok[x-1] << "\n";}}}