結果

問題 No.2325 Skill Tree
ユーザー zezerozezero
提出日時 2023-05-28 14:54:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 595 ms / 3,000 ms
コード長 1,155 bytes
コンパイル時間 3,399 ms
コンパイル使用メモリ 164,416 KB
実行使用メモリ 17,472 KB
最終ジャッジ日時 2023-08-27 10:51:23
合計ジャッジ時間 22,832 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 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 260 ms
5,200 KB
testcase_08 AC 178 ms
8,924 KB
testcase_09 AC 297 ms
7,052 KB
testcase_10 AC 225 ms
12,744 KB
testcase_11 AC 303 ms
9,984 KB
testcase_12 AC 550 ms
17,208 KB
testcase_13 AC 546 ms
17,472 KB
testcase_14 AC 550 ms
17,152 KB
testcase_15 AC 555 ms
17,284 KB
testcase_16 AC 549 ms
17,244 KB
testcase_17 AC 541 ms
17,208 KB
testcase_18 AC 541 ms
17,236 KB
testcase_19 AC 543 ms
17,204 KB
testcase_20 AC 541 ms
17,168 KB
testcase_21 AC 542 ms
17,272 KB
testcase_22 AC 554 ms
17,224 KB
testcase_23 AC 555 ms
17,288 KB
testcase_24 AC 556 ms
17,308 KB
testcase_25 AC 549 ms
17,368 KB
testcase_26 AC 552 ms
17,280 KB
testcase_27 AC 589 ms
16,500 KB
testcase_28 AC 595 ms
16,420 KB
testcase_29 AC 579 ms
16,660 KB
testcase_30 AC 591 ms
16,576 KB
testcase_31 AC 587 ms
16,360 KB
testcase_32 AC 566 ms
16,444 KB
testcase_33 AC 563 ms
16,504 KB
testcase_34 AC 565 ms
16,476 KB
testcase_35 AC 590 ms
16,432 KB
testcase_36 AC 585 ms
16,488 KB
testcase_37 AC 588 ms
16,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <cstring>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)
const ll INF = 1LL << 60;

int main(){
  int n;
  cin >> n;
  vector<ll> l(n);
  vector<int> a(n);
  vector<ll> d(n,INF);
  vector<vector<int>> g(n);
  d[0] = 0;
  for (int i = 1; i < n;i++){
    cin >> l[i] >> a[i];
    g[a[i]-1].push_back(i);
  }
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    auto x = q.front();
    //cout << x << endl;
    q.pop();
    for (auto nx:g[x]){
      d[nx] = d[x] + max(l[nx]-d[x],0LL);
      q.push(nx); 
    }
  }
  //cout << "ok" << endl;
  auto d2 = d;
  sort(d2.begin(),d2.end());
  int t;
  cin >> t;
  while(t--){
    int type,x;
    cin >> type >> x;
    if (type == 1){
      cout << int(lower_bound(d2.begin(),d2.end(),x+1)-d2.begin()) << endl;
    }
    else{
      if (d[x-1] == INF){
        cout << -1 << endl;
      }
      else cout << d[x-1] << endl;
    }

  }

  return 0;
}
0