結果
| 問題 | 
                            No.2325 Skill Tree
                             | 
                    
| コンテスト | |
| ユーザー | 
                             shop_one
                         | 
                    
| 提出日時 | 2023-05-28 14:10:26 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                MLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,494 bytes | 
| コンパイル時間 | 1,094 ms | 
| コンパイル使用メモリ | 122,372 KB | 
| 最終ジャッジ日時 | 2025-02-13 10:59:38 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 MLE * 16 | 
ソースコード
// 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;
    }
  }
}
            
            
            
        
            
shop_one