結果
問題 | No.2325 Skill Tree |
ユーザー | Rui |
提出日時 | 2023-05-28 14:14:29 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 565 ms / 3,000 ms |
コード長 | 1,728 bytes |
コンパイル時間 | 2,248 ms |
コンパイル使用メモリ | 179,124 KB |
実行使用メモリ | 15,152 KB |
最終ジャッジ日時 | 2023-08-27 09:20:52 |
合計ジャッジ時間 | 20,918 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 262 ms
4,640 KB |
testcase_08 | AC | 168 ms
8,120 KB |
testcase_09 | AC | 290 ms
6,432 KB |
testcase_10 | AC | 210 ms
11,304 KB |
testcase_11 | AC | 293 ms
8,864 KB |
testcase_12 | AC | 529 ms
14,796 KB |
testcase_13 | AC | 524 ms
14,852 KB |
testcase_14 | AC | 530 ms
15,152 KB |
testcase_15 | AC | 530 ms
14,868 KB |
testcase_16 | AC | 528 ms
14,908 KB |
testcase_17 | AC | 522 ms
14,972 KB |
testcase_18 | AC | 519 ms
14,856 KB |
testcase_19 | AC | 520 ms
14,748 KB |
testcase_20 | AC | 514 ms
14,860 KB |
testcase_21 | AC | 517 ms
14,792 KB |
testcase_22 | AC | 534 ms
14,864 KB |
testcase_23 | AC | 530 ms
14,792 KB |
testcase_24 | AC | 532 ms
14,812 KB |
testcase_25 | AC | 532 ms
14,812 KB |
testcase_26 | AC | 533 ms
14,740 KB |
testcase_27 | AC | 551 ms
14,240 KB |
testcase_28 | AC | 552 ms
14,064 KB |
testcase_29 | AC | 558 ms
13,964 KB |
testcase_30 | AC | 552 ms
14,024 KB |
testcase_31 | AC | 558 ms
14,112 KB |
testcase_32 | AC | 535 ms
14,060 KB |
testcase_33 | AC | 529 ms
14,076 KB |
testcase_34 | AC | 531 ms
14,120 KB |
testcase_35 | AC | 548 ms
14,040 KB |
testcase_36 | AC | 559 ms
14,016 KB |
testcase_37 | AC | 565 ms
14,120 KB |
ソースコード
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; typedef long long ll; //typedef modint1000000007 mint; const int MOD = 1000000007; #define all(x) x.begin(), x.end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) const int inf = 1 << 30; const ll INF = 1LL << 60; const int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1}; const int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1}; template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } int main(){ int n; cin >> n; vector<int> l(n), a(n); rep(i, n - 1) cin >> l[i + 1] >> a[i + 1]; vector<vector<int>> g(n); rep(i, n - 1) g[a[i + 1] - 1].push_back(i + 1); vector<bool> seen(n, false); vector<int> level(n, inf); seen[0] = true; level[0] = 0; queue<int> que; que.push(0); while(!que.empty()){ int v = que.front(); que.pop(); for(auto u : g[v]){ if(!seen[u]){ seen[u] = true; level[u] = max(l[u], level[v]); que.push(u); } } } vector<int> level2 = level; sort(all(level2)); //rep(i, n) cout << level2[i] << endl; int q; cin >> q; while(q--){ int num, x, y; cin >> num; if(num == 1){ cin >> x; auto it = upper_bound(all(level2), x); cout << it - level2.begin() << endl; } if(num == 2){ cin >> y; if(level[y - 1] == inf) cout << -1 << endl; else cout << level[y - 1] << endl; } } return 0; }