結果
| 問題 |
No.2325 Skill Tree
|
| コンテスト | |
| ユーザー |
houren
|
| 提出日時 | 2023-05-28 15:32:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 190 ms / 3,000 ms |
| コード長 | 1,391 bytes |
| コンパイル時間 | 1,808 ms |
| コンパイル使用メモリ | 180,592 KB |
| 実行使用メモリ | 14,308 KB |
| 最終ジャッジ日時 | 2024-12-27 07:15:36 |
| 合計ジャッジ時間 | 9,353 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n,q;
cin >> n;
vector<vector<int>> g(n);
vector<int> l(n);
rep(i,n-1){
int a;
cin >> l[i+1] >> a;
g[a-1].push_back(i+1);
}
vector<int> dist(n,INF), r(1,0);
dist[0] = 0;
priority_queue<asc(P)> pq;
pq.push({0,0});
while(pq.size()){
int now, d;
tie(d,now) = pq.top();
pq.pop();
if(dist[now]!=d) continue;
r.push_back(d);
for(int x:g[now]){
if(chmin(dist[x], max(dist[now], l[x]))) pq.push({dist[x], x});
}
}
rep(i,n) if(dist[i]==INF) dist[i] = -1;
cin >> q;
rep(houren,q){
int t,x;
cin >> t >> x;
if(t==1){
cout << upper_bound(all(r),x) - r.begin()-1 << '\n';
}else{
cout << dist[x-1] << '\n';
}
}
return 0;
}
houren