結果

問題 No.2325 Skill Tree
ユーザー 蜜蜂蜜蜂
提出日時 2023-05-28 14:24:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 422 ms / 3,000 ms
コード長 1,553 bytes
コンパイル時間 4,040 ms
コンパイル使用メモリ 233,500 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2023-08-27 09:42:22
合計ジャッジ時間 19,003 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 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 203 ms
4,644 KB
testcase_08 AC 119 ms
7,492 KB
testcase_09 AC 223 ms
6,032 KB
testcase_10 AC 143 ms
10,364 KB
testcase_11 AC 212 ms
8,232 KB
testcase_12 AC 390 ms
13,560 KB
testcase_13 AC 385 ms
13,448 KB
testcase_14 AC 388 ms
13,520 KB
testcase_15 AC 392 ms
13,512 KB
testcase_16 AC 382 ms
13,516 KB
testcase_17 AC 389 ms
13,512 KB
testcase_18 AC 387 ms
13,588 KB
testcase_19 AC 378 ms
13,428 KB
testcase_20 AC 384 ms
13,540 KB
testcase_21 AC 382 ms
13,500 KB
testcase_22 AC 386 ms
13,564 KB
testcase_23 AC 383 ms
13,516 KB
testcase_24 AC 388 ms
13,640 KB
testcase_25 AC 386 ms
13,600 KB
testcase_26 AC 387 ms
13,588 KB
testcase_27 AC 417 ms
13,112 KB
testcase_28 AC 422 ms
13,036 KB
testcase_29 AC 412 ms
12,976 KB
testcase_30 AC 420 ms
13,060 KB
testcase_31 AC 417 ms
12,920 KB
testcase_32 AC 404 ms
12,952 KB
testcase_33 AC 412 ms
13,052 KB
testcase_34 AC 407 ms
12,972 KB
testcase_35 AC 408 ms
12,988 KB
testcase_36 AC 414 ms
12,972 KB
testcase_37 AC 422 ms
12,960 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void dfs(int, int, std::vector<std::vector<std::pair<int, int> > >&, vi&)’ 内:
main.cpp:32:12: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   32 |   for(auto [lv,nxt]:g[now]){
      |            ^

ソースコード

diff #

// g++ 1.cpp -std=c++17 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;
 
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;
 
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

void dfs(int now,int pre,vector<vector<pair<int,int>>> &g,vi &need){
  for(auto [lv,nxt]:g[now]){
    if(nxt==pre)continue;
    need[nxt]=max(need[now],lv);
    dfs(nxt,now,g,need);
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;cin>>n;
  vi need(n,1e9+10);
  vector<vector<pair<int,int>>> g(n);
  rep(i,0,n-1){
    int l,a;cin>>l>>a;
    a--;
    g[a].emplace_back(l,(int)i+1); // cost,to
  }

  need[0]=0;
  dfs(0,-1,g,need);

  vi n2=need;
  sort(all(n2));

  int q;cin>>q;
  while(q--){
    int t;cin>>t;

    if(t==1){
      int x;cin>>x;
      cout<<upper_bound(all(n2),x)-n2.begin()<<endl;
    }
    else{
      int y;cin>>y;
      y--;
      if(need[y]==1e9+10){
        need[y]=-1;
      }
      cout<<need[y]<<endl;
    }
  }
}
0