結果
問題 | No.2325 Skill Tree |
ユーザー |
![]() |
提出日時 | 2024-12-06 13:13:43 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 157 ms / 3,000 ms |
コード長 | 1,050 bytes |
コンパイル時間 | 2,752 ms |
コンパイル使用メモリ | 218,848 KB |
実行使用メモリ | 13,824 KB |
最終ジャッジ日時 | 2024-12-06 13:13:56 |
合計ジャッジ時間 | 12,779 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h>using namespace std;void fast_io() {ios_base::sync_with_stdio(false);cin.tie(nullptr);}int main() {fast_io();int n;cin >> n;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});}deque<int> dq{0};vector<int> dp(n, -1);dp[0] = 0;while (!dq.empty()) {int v = dq.front();dq.pop_front();for (auto [u, l] : g[v]) {if (dp[u] == -1) {dp[u] = max(dp[v], l);dq.push_back(u);}}}map<int, int> cnt;for (int i = 0; i < n; i++) {if (dp[i] != -1) {cnt[dp[i]]++;}}vector<pair<int, int>> cnts;for (auto [l, c] : cnt) {cnts.push_back({l, c});}for (int i = 1; i < cnts.size(); i++) {cnts[i].second += cnts[i - 1].second;}int q;cin >> q;for (; q--;) {int query, x;cin >> query >> x;if (query == 1) {auto it =lower_bound(cnts.begin(), cnts.end(), make_pair(x + 1, 0));cout << prev(it)->second << '\n';} else {cout << dp[x - 1] << "\n";}}}