結果

問題 No.2325 Skill Tree
ユーザー MMMM
提出日時 2023-05-28 13:54:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 634 ms / 3,000 ms
コード長 1,193 bytes
コンパイル時間 1,895 ms
コンパイル使用メモリ 179,928 KB
実行使用メモリ 14,420 KB
最終ジャッジ日時 2023-08-27 08:39:04
合計ジャッジ時間 21,956 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 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,380 KB
testcase_07 AC 259 ms
4,516 KB
testcase_08 AC 175 ms
7,656 KB
testcase_09 AC 292 ms
6,136 KB
testcase_10 AC 224 ms
10,656 KB
testcase_11 AC 297 ms
8,576 KB
testcase_12 AC 542 ms
14,052 KB
testcase_13 AC 537 ms
13,936 KB
testcase_14 AC 547 ms
14,000 KB
testcase_15 AC 543 ms
14,004 KB
testcase_16 AC 540 ms
14,060 KB
testcase_17 AC 531 ms
13,960 KB
testcase_18 AC 537 ms
14,068 KB
testcase_19 AC 528 ms
13,920 KB
testcase_20 AC 535 ms
14,048 KB
testcase_21 AC 528 ms
13,952 KB
testcase_22 AC 542 ms
14,112 KB
testcase_23 AC 542 ms
14,048 KB
testcase_24 AC 545 ms
14,116 KB
testcase_25 AC 544 ms
14,044 KB
testcase_26 AC 543 ms
14,056 KB
testcase_27 AC 620 ms
14,268 KB
testcase_28 AC 617 ms
14,228 KB
testcase_29 AC 615 ms
14,268 KB
testcase_30 AC 613 ms
14,244 KB
testcase_31 AC 612 ms
14,420 KB
testcase_32 AC 592 ms
14,292 KB
testcase_33 AC 600 ms
14,416 KB
testcase_34 AC 597 ms
14,232 KB
testcase_35 AC 623 ms
14,392 KB
testcase_36 AC 613 ms
14,256 KB
testcase_37 AC 634 ms
14,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define chmin(x,y) (x) = min((x),(y))
#define chmax(x,y) (x) = max((x),(y))
using namespace std;
using ll = long long;
const ll mod = 998244353;
const vector<int> dx = {1,0,-1,0}, dy = {0,1,0,-1};
using Graph = vector<vector<int>>;

int main(){
  // input
  int N; cin >> N;
  Graph G(N);
  vector<int> L(N),A(N);
  for (int i = 1; i < N; i++){
    cin >> L[i] >> A[i];
    A[i]--; // manage skills ID by 0-indexed
    G[A[i]].push_back(i);
  }
  
  // prep: dijkstra
  vector<int> v,lv(N,2e9);
  priority_queue<pair<int,int>> pq;
  
  pq.emplace(0,0); lv[0] = 0;
  
  while(!pq.empty()){
    int cur_l = pq.top().first, cur_s = pq.top().second;
    pq.pop();
    for(auto nxt : G[cur_s]){
      int nec_l = max(L[nxt],-cur_l);
      if(lv[nxt] > nec_l){
        lv[nxt] = nec_l;
        pq.emplace(-nec_l,nxt);
      }
    }
  }
  
  for(int i = 0; i < N; i++)
    if(lv[i] < 2e9)
      v.push_back(lv[i]);
  sort(v.begin(),v.end());
  
  // solve + output
  int Q; cin >> Q;
  while(Q--){
    int q,x; cin >> q >> x;
    if(q == 1)
      cout << upper_bound(v.begin(),v.end(),x) - v.begin() << endl;
    else
      cout << (lv[x-1] < 2e9? lv[x-1] : -1) << endl;
  }
}
0