結果

問題 No.2325 Skill Tree
ユーザー yansi819
提出日時 2024-04-08 11:13:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 717 ms / 3,000 ms
コード長 911 bytes
コンパイル時間 4,690 ms
コンパイル使用メモリ 260,028 KB
最終ジャッジ日時 2025-02-20 22:59:24
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

int main() {
  int N; cin >> N;
  vector<int> L(N), A(N);
  vector<vector<pair<int, int>>> G(N);
  for (int i = 1; i < N; i++) {
    cin >> L[i] >> A[i]; A[i]--;
    G[A[i]].push_back({i, L[i]});
  }
  vector<int> ds(N, -1), ls;
  ds[0] = 0;
  queue<int> que;
  que.push(0);
  while (!que.empty()) {
    int u = que.front(); que.pop();
    ls.push_back(ds[u]);

    for (auto &x: G[u]) {
      int v = x.first, vd = max(ds[u], x.second);
      ds[v] = vd;
      que.push(v);
    }
  }
  sort(ls.begin(), ls.end());

  int Q; cin >> Q;
  while (Q--) {
    int t, x; cin >> t >> x;
    if (t == 1) {
      cout << upper_bound(ls.begin(), ls.end(), x) - ls.begin() << endl;
    } else {
      cout << ds[x - 1] << endl;
    }
  }
  return 0;
}
0