結果
| 問題 |
No.2325 Skill Tree
|
| コンテスト | |
| ユーザー |
gyozasukisuki
|
| 提出日時 | 2023-05-28 15:28:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,564 bytes |
| コンパイル時間 | 2,168 ms |
| コンパイル使用メモリ | 208,852 KB |
| 最終ジャッジ日時 | 2025-02-13 13:26:57 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 TLE * 11 |
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
const int INF = 1e9;
using ll = long long;
using inv = vector<int>;
using stv = vector<string>;
using pint = pair<int,int>;
#define FOR(i,l,r) for(int i=(l); i<(r); i++)
#define rep(i,r) for(int i=0; i<(r); i++)
#define repl(i,r) for(long long i=0; i<(r); i++)
#define FORl(i,l,r) for(long long i=(l); i<(r); i++)
#define INFL ((1LL<<62)-(1LL<<31))
#define pb(x) push_back(x)
#define CIN(x) cin >> x
// to and cost
using Graph = vector<vector<pair<ll,ll>>>;
void dfs(Graph G,int v,ll nowlv, vector<ll> &lv, vector<bool> &seen){
seen[v] = true;
lv[v] = nowlv;
if(G[v].size() == 0) return;
for(auto [nexv,l] : G[v]){
if(seen[nexv]) continue;
dfs(G,nexv,(nowlv > l ? nowlv:l),lv,seen);
}
}
int main(){
ll N;
cin >> N;
Graph G(N,vector<pair<ll,ll>>());
vector<ll> minl(N,-1LL);
vector<bool> seen(N,false);
seen[0] = true;
rep(i,N-1){
ll L,A;
cin >> L >> A;
A--;
G[A].pb(make_pair(i+1,L));
}
dfs(G,0,1,minl,seen);
// rep(i,N) cout << minl[i] << " ";
// cout<< endl;
vector<ll> smin;
smin = minl;
sort(smin.begin(),smin.end());
ll cnt = count(smin.begin(),smin.end(),-1);
ll Q;
cin >> Q;
rep(q,Q){
int t;
cin >> t;
if(t == 1){
ll x;
cin >> x;
ll ans= (ll)(upper_bound(smin.begin(),smin.end(),x)-smin.begin());
ans -= cnt;
cout << ans << endl;
}else{
int y;
cin >> y;
y--;
cout << minl[y] << endl;
}
}
}
gyozasukisuki