結果

問題 No.2325 Skill Tree
ユーザー shop_oneshop_one
提出日時 2023-05-28 14:10:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,494 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 125,600 KB
実行使用メモリ 814,460 KB
最終ジャッジ日時 2023-08-27 09:09:34
合計ジャッジ時間 4,535 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
ll calc(int i, vector<ll> &dp, vector<ll> &a, vector<vector<ll>> &G) {
  if (dp[i] != -1) return dp[i];
  ll tmp = a[i];
  for(auto nv: G[i]) {
    tmp = max(tmp, calc(nv, dp, a, G));
  }
  return dp[i] = tmp;
}
signed main(){
  init_io();
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<vector<ll>> G(n, vector<ll>());
  int is_cicle = true;
  a[0] = 0;
  vector<ll> dp(n, -1);
  dp[0] = 0;
  for (int i=1;i<n;i++) {
    ll x, y;
    cin >> y >> x;
    if (x == 1) is_cicle = false;
    x--;
    G[i].push_back(x);
    a[i] = y;
  }
  map<ll, ll> mp;
  mp[0]++;
  vector<ll> copy(n);
  copy[0] = 0;
  if (!is_cicle) {
    for (int i=1;i<n;i++) {
      int tmp = calc(i, dp, a, G);
      copy[i] = tmp;
    }
  }
  sort(copy.begin(), copy.end());
  for(int i=0;i<n;i++) {
    mp[copy[i]] = i+1;
  }
  int q;
  cin >> q;
  for (int i=0;i<q;i++) {
    int x,y;
    cin >> x >> y;
    if (x == 1) {
      if (is_cicle) {
        cout << 1 << endl;
      } else {
        auto itr = mp.upper_bound(y);
        itr--;
        cout << itr->second << endl;
      }
    }
    if (x == 2) {
      cout << dp[y-1] << endl;
    }
  }
}
0