結果

問題 No.2325 Skill Tree
ユーザー rurunrurun
提出日時 2023-05-28 14:17:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 591 ms / 3,000 ms
コード長 921 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 209,524 KB
実行使用メモリ 14,972 KB
最終ジャッジ日時 2023-08-27 09:27:24
合計ジャッジ時間 22,002 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 260 ms
4,536 KB
testcase_08 AC 176 ms
7,700 KB
testcase_09 AC 293 ms
6,432 KB
testcase_10 AC 225 ms
11,308 KB
testcase_11 AC 299 ms
8,896 KB
testcase_12 AC 550 ms
14,760 KB
testcase_13 AC 545 ms
14,816 KB
testcase_14 AC 550 ms
14,740 KB
testcase_15 AC 547 ms
14,920 KB
testcase_16 AC 541 ms
14,744 KB
testcase_17 AC 544 ms
14,812 KB
testcase_18 AC 540 ms
14,828 KB
testcase_19 AC 531 ms
14,940 KB
testcase_20 AC 540 ms
14,836 KB
testcase_21 AC 534 ms
14,812 KB
testcase_22 AC 550 ms
14,972 KB
testcase_23 AC 550 ms
14,812 KB
testcase_24 AC 549 ms
14,868 KB
testcase_25 AC 553 ms
14,820 KB
testcase_26 AC 553 ms
14,816 KB
testcase_27 AC 584 ms
14,004 KB
testcase_28 AC 575 ms
14,032 KB
testcase_29 AC 573 ms
14,144 KB
testcase_30 AC 578 ms
14,084 KB
testcase_31 AC 585 ms
13,968 KB
testcase_32 AC 558 ms
14,136 KB
testcase_33 AC 561 ms
14,128 KB
testcase_34 AC 557 ms
14,208 KB
testcase_35 AC 584 ms
13,948 KB
testcase_36 AC 580 ms
14,020 KB
testcase_37 AC 591 ms
14,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
int main() {
  int n;
  cin >> n;
  vector<vector<int>> vec(n);
  vector<int> par(n, -1), lev(n, 0);
  for (int i = 1; i < n; i++) {
    cin >> lev[i] >> par[i];
    par[i]--;
    vec[par[i]].push_back(i);
  }
  vector<int> min_lev(n, (1<<30));
  min_lev[0] = 0;
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int p = q.front();
    q.pop();
    for (auto x : vec[p]) {
      min_lev[x] = max(lev[x], min_lev[p]);
      q.push(x);
    }
  }
  vector cop = min_lev;
  sort(cop.begin(), cop.end());
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int t, x;
    cin >> t >> x;
    if (t == 1) {
      auto itr = upper_bound(cop.begin(), cop.end(), x)-cop.begin();
      cout << itr << endl;
    }
    else if (t == 2) {
    	x--;
      if (min_lev[x] == (1<<30)) cout << -1 << endl;
      else cout << min_lev[x] << endl;

    }
  }

}
0