結果
| 問題 |
No.2325 Skill Tree
|
| コンテスト | |
| ユーザー |
hiro71687k
|
| 提出日時 | 2023-06-07 23:57:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 569 ms / 3,000 ms |
| コード長 | 1,588 bytes |
| コンパイル時間 | 3,876 ms |
| コンパイル使用メモリ | 261,116 KB |
| 最終ジャッジ日時 | 2025-02-13 23:20:17 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
#include<atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=20000000000000;
ll mod=998244353;
int main(){
ll n;
cin >> n;
vector<ll>l(n),a(n);
vector<vector<ll>>g(n);
l[0]=0;
for (ll i = 1; i < n; i++)
{
cin >> l[i]>> a[i];
a[i]--;
g[a[i]].push_back(i);
}
ll q;
cin >> q;
queue<ll>que;
que.push(0);
vector<ll>memo(n,0);
while (!que.empty())
{
ll v=que.front();
que.pop();
memo[v]=1;
for (ll i = 0; i < g[v].size(); i++)
{
if (memo[g[v][i]]==0)
{
l[g[v][i]]=max(l[g[v][i]],l[v]);
que.push(g[v][i]);
}
}
}
for (ll i = 0; i < n; i++)
{
if (memo[i]==0)
{
l[i]=inf;
}
}
vector<ll>x=l;
x.push_back(inf);
sort(x.begin(),x.end());
vector<ll>ans;
for (ll i = 0; i < q; i++)
{
ll t;
cin >> t;
if (t==1)
{
ll xx;
cin >> xx;
ll v=lower_bound(x.begin(),x.end(),xx+1)-x.begin();
ans.push_back(v);
}else{
ll y;
cin >> y;
if (l[y-1]==inf)
{
ans.push_back(-1);
continue;
}
ans.push_back(l[y-1]);
}
}
for (ll i = 0; i < ans.size(); i++)
{
cout << ans[i] << endl;
}
}
hiro71687k