結果

問題 No.2325 Skill Tree
ユーザー 蜜蜂
提出日時 2023-05-28 14:24:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 411 ms / 3,000 ms
コード長 1,553 bytes
コンパイル時間 3,917 ms
コンパイル使用メモリ 236,164 KB
実行使用メモリ 13,796 KB
最終ジャッジ日時 2024-12-27 01:02:11
合計ジャッジ時間 18,615 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void dfs(int, int, std::vector<std::vector<std::pair<int, int> > >&, vi&)':
main.cpp:32:12: warning: 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;
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0