結果
問題 | No.2325 Skill Tree |
ユーザー | coindarw |
提出日時 | 2023-05-28 14:40:55 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 169 ms / 3,000 ms |
コード長 | 2,584 bytes |
コンパイル時間 | 4,851 ms |
コンパイル使用メモリ | 266,592 KB |
実行使用メモリ | 13,348 KB |
最終ジャッジ日時 | 2023-08-27 10:19:48 |
合計ジャッジ時間 | 12,538 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 40 ms
4,380 KB |
testcase_08 | AC | 45 ms
7,052 KB |
testcase_09 | AC | 52 ms
5,884 KB |
testcase_10 | AC | 66 ms
9,932 KB |
testcase_11 | AC | 63 ms
7,792 KB |
testcase_12 | AC | 126 ms
12,768 KB |
testcase_13 | AC | 126 ms
12,732 KB |
testcase_14 | AC | 128 ms
12,764 KB |
testcase_15 | AC | 128 ms
12,864 KB |
testcase_16 | AC | 126 ms
12,704 KB |
testcase_17 | AC | 124 ms
12,768 KB |
testcase_18 | AC | 121 ms
12,780 KB |
testcase_19 | AC | 123 ms
12,728 KB |
testcase_20 | AC | 125 ms
13,004 KB |
testcase_21 | AC | 124 ms
12,868 KB |
testcase_22 | AC | 131 ms
12,744 KB |
testcase_23 | AC | 131 ms
12,828 KB |
testcase_24 | AC | 128 ms
12,772 KB |
testcase_25 | AC | 125 ms
12,760 KB |
testcase_26 | AC | 125 ms
12,744 KB |
testcase_27 | AC | 164 ms
13,224 KB |
testcase_28 | AC | 166 ms
13,336 KB |
testcase_29 | AC | 165 ms
13,220 KB |
testcase_30 | AC | 163 ms
13,340 KB |
testcase_31 | AC | 169 ms
13,240 KB |
testcase_32 | AC | 156 ms
13,224 KB |
testcase_33 | AC | 153 ms
13,300 KB |
testcase_34 | AC | 155 ms
13,348 KB |
testcase_35 | AC | 156 ms
13,216 KB |
testcase_36 | AC | 163 ms
13,228 KB |
testcase_37 | AC | 169 ms
13,228 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using ll = long long; #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define rreps(i, n) for (int i = ((int)(n)); i > 0; --i) #define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i) #define repc2(i, s, n) for (int i = (s); i <= (int)(n); ++i) constexpr int inf = 2000'000'000; constexpr ll linf = 4000000000000000000ll; constexpr ll M7 = 1000000007ll; constexpr ll M09 = 1000000009ll; constexpr ll M9 = 998244353ll; #define all(v) begin(v), end(v) #define rall(v) rbegin(v), rend(v) using namespace std; using namespace atcoder; template <typename T> inline ostream& operator<<(ostream& os, vector<T>& v) { for (auto& e : v) os << e << " "; return os; } template <typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) noexcept { return os << "(" << p.first << ", " << p.second << ")"; } #ifdef ONLINE_JUDGE #define debug(...) #else #define debug(...) cerr << "<" << #__VA_ARGS__ << ">: ", debug_out(__VA_ARGS__) template <typename T> void debug_out(T t) { cerr << t << endl; } template <typename T, typename... Args> void debug_out(T t, Args... args) { cerr << t << ", "; debug_out(args...); } #endif int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; struct edge { int to, cost; edge(int to, int cost) : to(to), cost(cost) {} }; vector<vector<edge>> G(n); rep(i, n - 1) { int l, a; cin >> l >> a; G.at(a - 1).push_back(edge(i + 1, l)); } vector<bool> seen(n); vector<int> a(n, -inf); auto dfs = [&](auto dfs, int u) -> void { seen.at(u) = true; for (const auto& e : G.at(u)) { if (seen.at(e.to)) continue; a.at(e.to) = max(a.at(u), e.cost); dfs(dfs, e.to); } }; a.at(0) = 0; dfs(dfs, 0); vector<int> sorted; rep(i, n) { if (a.at(i) != -inf) sorted.push_back(a.at(i)); } sort(all(sorted)); int q; cin >> q; rep(i, q) { int c, x; cin >> c >> x; if (c == 1) { auto ub = upper_bound(all(sorted), x); cout << (ub - sorted.begin()) << "\n"; } else { if (a.at(x - 1) == -inf) cout << -1 << "\n"; else cout << a.at(x - 1) << "\n"; } } return 0; }