結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 264 ms
4,564 KB
testcase_08 AC 178 ms
7,912 KB
testcase_09 AC 297 ms
6,720 KB
testcase_10 AC 226 ms
11,240 KB
testcase_11 AC 303 ms
9,116 KB
testcase_12 AC 550 ms
14,828 KB
testcase_13 AC 553 ms
15,116 KB
testcase_14 AC 549 ms
14,968 KB
testcase_15 AC 548 ms
14,972 KB
testcase_16 AC 547 ms
14,788 KB
testcase_17 AC 537 ms
14,844 KB
testcase_18 AC 536 ms
15,080 KB
testcase_19 AC 541 ms
14,792 KB
testcase_20 AC 537 ms
14,968 KB
testcase_21 AC 542 ms
14,860 KB
testcase_22 AC 555 ms
14,972 KB
testcase_23 AC 552 ms
14,816 KB
testcase_24 AC 554 ms
14,840 KB
testcase_25 AC 556 ms
14,844 KB
testcase_26 AC 552 ms
14,972 KB
testcase_27 AC 581 ms
14,000 KB
testcase_28 AC 581 ms
14,292 KB
testcase_29 AC 586 ms
14,132 KB
testcase_30 AC 583 ms
13,996 KB
testcase_31 AC 582 ms
14,352 KB
testcase_32 AC 552 ms
14,016 KB
testcase_33 AC 563 ms
14,176 KB
testcase_34 AC 561 ms
14,056 KB
testcase_35 AC 587 ms
14,188 KB
testcase_36 AC 585 ms
14,116 KB
testcase_37 AC 593 ms
14,068 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