結果
| 問題 |
No.2325 Skill Tree
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-28 14:56:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 531 ms / 3,000 ms |
| コード長 | 1,224 bytes |
| コンパイル時間 | 2,094 ms |
| コンパイル使用メモリ | 208,436 KB |
| 最終ジャッジ日時 | 2025-02-13 12:17:27 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
#include "atcoder/modint"
using i64 = long long;
using Fp = atcoder::modint998244353;
int main() {
int N;
std::cin >> N;
std::vector<int> L(N), A(N);
std::vector<std::vector<int>> graph(N);
for (int i = 1; i < N; ++i) {
std::cin >> L[i] >> A[i];
--A[i];
graph[A[i]].push_back(i);
}
std::vector<int> dist(N, -1);
dist[0] = 0;
std::queue<int> que;
que.push(0);
while (not que.empty()) {
const auto f = que.front();
que.pop();
for (const auto t : graph[f]) {
i64 c = std::max(dist[f], L[t]);
dist[t] = c;
que.push(t);
}
}
std::vector<i64> x;
for (const auto e : dist) if (e != -1) x.push_back(e);
std::sort(x.begin(), x.end());
int Q;
std::cin >> Q;
while (Q--) {
int t;
std::cin >> t;
if (t == 1) {
int v;
std::cin >> v;
auto itr = std::upper_bound(x.begin(), x.end(), v);
std::cout << (itr - x.begin()) << std::endl;
} else {
int v;
std::cin >> v;
--v;
std::cout << dist[v] << std::endl;
}
}
}