結果
問題 | No.2325 Skill Tree |
ユーザー |
|
提出日時 | 2023-05-28 13:43:46 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 627 ms / 3,000 ms |
コード長 | 890 bytes |
コンパイル時間 | 949 ms |
コンパイル使用メモリ | 84,976 KB |
実行使用メモリ | 15,232 KB |
最終ジャッジ日時 | 2024-12-26 21:38:54 |
合計ジャッジ時間 | 20,961 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#include<iostream> #include<vector> #include<queue> #include<algorithm> #include<cassert> using namespace std; int N,Q; vector<int>G[2<<17]; int L[2<<17]; bool vis[2<<17]; int main() { cin>>N; for(int i=1;i<N;i++) { int A; cin>>L[i]>>A; G[A-1].push_back(i); } priority_queue<pair<int,int> >pq; pq.push(make_pair(0,0)); while(!pq.empty()) { int u=pq.top().second; int c=-pq.top().first; pq.pop(); if(vis[u])continue; vis[u]=true; L[u]=max(L[u],c); for(int v:G[u]) { assert(!vis[v]); pq.push(make_pair(-L[u],v)); } } vector<int>Lv(N); for(int i=0;i<N;i++) { if(vis[i])Lv[i]=L[i]; else Lv[i]=2e9; } sort(Lv.begin(),Lv.end()); cin>>Q; for(;Q--;) { int op;cin>>op; if(op==1) { int x;cin>>x; cout<<upper_bound(Lv.begin(),Lv.end(),x)-Lv.begin()<<"\n"; } else { int y;cin>>y; y--; cout<<(vis[y]?L[y]:-1)<<"\n"; } } }