結果
| 問題 |
No.2325 Skill Tree
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-28 15:14:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,472 bytes |
| コンパイル時間 | 1,892 ms |
| コンパイル使用メモリ | 201,744 KB |
| 最終ジャッジ日時 | 2025-02-13 12:50:09 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 WA * 2 TLE * 28 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = unsigned long long;
using Graph = vector<vector<int>>;
int main()
{
int n;
cin >> n;
vector<pair<int, int>> waza(n);
waza.at(0) = make_pair(0, 0);
for (int i = 1; i < n; i++)
{
int l, a;
cin >> l >> a;
l--;
a--;
waza.at(i) = make_pair(l, a);
}
int Q;
cin >> Q;
rep(i, Q)
{
int q, x;
cin >> q >> x;
x--;
if (q == 1)
{
int ans = 1;
set<int> oboe;
oboe.insert(0);
for (int j = 1; j < n; j++)
{
if (waza.at(j).first <= x && oboe.count(waza.at(j).second))
{
oboe.insert(j);
ans++;
}
}
cout << ans << endl;
}
else if (q == 2)
{
int ans = -1;
set<int> used_x;
while (1)
{
ans = max(waza.at(x).first, ans);
x = waza.at(x).second;
if (x == 0)
{
cout << ans + 1 << endl;
break;
}
if (used_x.count(x))
{
cout << -1 << endl;
break;
}
used_x.insert(x);
}
}
}
}