結果
問題 |
No.2325 Skill Tree
|
ユーザー |
![]() |
提出日時 | 2023-06-24 02:29:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 185 ms / 3,000 ms |
コード長 | 1,214 bytes |
コンパイル時間 | 675 ms |
コンパイル使用メモリ | 62,044 KB |
実行使用メモリ | 13,184 KB |
最終ジャッジ日時 | 2024-07-01 06:03:56 |
合計ジャッジ時間 | 11,418 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
/* -*- coding: utf-8 -*- * * 2325.cc: No.2325 Skill Tree - yukicoder */ #include<cstdio> #include<vector> #include<queue> #include<algorithm> #include<utility> using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ typedef queue<int> qi; typedef pair<int,int> pii; typedef vector<pii> vpii; /* global variables */ vpii nbrs[MAX_N]; int ds[MAX_N], ls[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 1; i < n; i++) { int li, ai; scanf("%d%d", &li, &ai), ai--; nbrs[ai].push_back(pii(i, li)); } fill(ds, ds + n, -1); ds[0] = 0; qi q; q.push(0); int k = 0; while (! q.empty()) { int u = q.front(); q.pop(); ls[k++] = ds[u]; for (auto &vw: nbrs[u]) { int v = vw.first, vd = max(ds[u], vw.second); ds[v] = vd; q.push(v); } } sort(ls, ls + k); int qn; scanf("%d", &qn); while (qn--) { int op; scanf("%d", &op); if (op == 1) { int x; scanf("%d", &x); int c = upper_bound(ls, ls + k, x) - ls; printf("%d\n", c); } else { int y; scanf("%d", &y), y--; printf("%d\n", ds[y]); } } return 0; }