結果

問題 No.2325 Skill Tree
ユーザー ma_twma_tw
提出日時 2023-05-28 15:11:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 174 ms / 3,000 ms
コード長 4,544 bytes
コンパイル時間 2,610 ms
コンパイル使用メモリ 216,876 KB
実行使用メモリ 14,436 KB
最終ジャッジ日時 2024-06-08 07:10:56
合計ジャッジ時間 10,484 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 41 ms
6,940 KB
testcase_08 AC 42 ms
7,808 KB
testcase_09 AC 53 ms
6,944 KB
testcase_10 AC 61 ms
10,752 KB
testcase_11 AC 63 ms
8,696 KB
testcase_12 AC 136 ms
14,192 KB
testcase_13 AC 124 ms
14,292 KB
testcase_14 AC 125 ms
14,192 KB
testcase_15 AC 128 ms
14,184 KB
testcase_16 AC 124 ms
14,192 KB
testcase_17 AC 119 ms
14,272 KB
testcase_18 AC 120 ms
14,260 KB
testcase_19 AC 118 ms
14,268 KB
testcase_20 AC 120 ms
14,072 KB
testcase_21 AC 119 ms
14,292 KB
testcase_22 AC 119 ms
14,204 KB
testcase_23 AC 120 ms
14,208 KB
testcase_24 AC 116 ms
14,364 KB
testcase_25 AC 120 ms
14,272 KB
testcase_26 AC 116 ms
14,180 KB
testcase_27 AC 164 ms
14,372 KB
testcase_28 AC 165 ms
14,380 KB
testcase_29 AC 163 ms
14,316 KB
testcase_30 AC 162 ms
14,296 KB
testcase_31 AC 163 ms
14,312 KB
testcase_32 AC 135 ms
14,168 KB
testcase_33 AC 146 ms
14,324 KB
testcase_34 AC 146 ms
14,380 KB
testcase_35 AC 155 ms
14,092 KB
testcase_36 AC 152 ms
13,904 KB
testcase_37 AC 174 ms
14,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#pragma region
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvvi = vector<vector<vector<int>>>;
using vpi = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using pi = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T = int> using spq = priority_queue<T, vector<T>, greater<T>>;
template<typename T = int> using gpq = priority_queue<T>;
#define fi first
#define se second
#define fore(p,a) for (auto p : a)
#define overload4(a,b,c,d,name,...) name
#define rep1(n) for (int i = 0; i < int (n); ++i)
#define rep2(i,n) for (int i = 0; i < int (n); ++i)
#define rep3(i,a,b) for (int i = a; i < int (b); ++i)
#define rep4(i,a,b,c) for (int i = a; i < int (b); i += c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(n) for (int i = n; i--;)
#define rrep2(i,n) for (int i = n; i--;)
#define rrep3(i,a,b) for (int i = b; i-- > (a);)
#define rrep4(i,a,b,c) for (int i = (a) + ((b) - (a) - 1) / (c) * (c); i >= (a); i -= c)
#define rrep(...) overload4(__VA_ARGS__,rrep4,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define all(container) begin(container), end(container)
#define rall(container) rbegin(container), rend(container)
#define mvvi(name, row, column) vvi name(row, vi(column))
#define mvvll(name, row, column) vvll name(row, vll(column))
#define mvvb(name, row, column) vvb name(row, vb(column))
#define Max(...) max({__VA_ARGS__})
#define Min(...) min({__VA_ARGS__})
#define fin exit(0)
#define popc __builtin_popcount
#define inrange(x, l, r) ((l) <= (x) && (x) < (r))
#define sq(x) ((x) * (x))
#ifdef LOCAL
template<typename T> string internal_vectostr(vector<T> v) { string ret; for (int i = 0; i < (int) v.size(); i++) ret += (i ? ", " : "") + to_string(v[i]); return ret; }
#define dbg(x) cerr << "[DEBUG] " << __LINE__ << ": " << #x << " = " << x << endl
#define dbv(x) cerr << "[DEBUG] " << __LINE__ << ": " << #x << " = { " << internal_vectostr(x) << " }" << endl
#define tabout(tab, n, m) cout << "[DEBUG]\n"; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cout << tab[i][j] << ' '; cout << endl; }
#else
template<typename T> void internal_vectostr(vector<T> v) {}
#define dbg(x) ((void) 0)
#define dbv(x) ((void) 0)
#define tabout(tab, n, m) ((void) 0)
#endif
constexpr int INF = 1001001001;
constexpr ll LINF = 1LL << 60;
constexpr double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll fact(ll x) { return x == 0 ? 1 : x * fact(x - 1); }
ll comb(ll n, ll r) { if (r < 0 || n < r) return 0; ll ret = 1; for (ll i = 1; i <= r; i++) { ret *= n; n--; ret /= i; } return ret; }
int Yes(bool f=1) { cout << (f ? "Yes" : "No") << '\n'; return 0; }
int No() { Yes(0); return 0; }
int YES(bool f=1) { cout << (f ? "YES" : "NO") << '\n'; return 0; }
int NO() { YES(0); return 0; }
int yes(bool f=1) { cout << (f ? "yes" : "no") << '\n'; return 0; }
int no() { yes(0); return 0; }
template<class T> int printvec(vector<T> v) { for (int i = 0; i < (int) v.size(); i++) cout << (i ? " " : "") << v[i]; cout << '\n'; return 0; }
struct IoInit { IoInit() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << setprecision(15) << fixed; cerr << setprecision(15) << fixed; } } io_init;
#pragma endregion

int main(){
    int n;
    cin>>n;
    vi l(n+1),a(n+1);
    for(int i=2;i<=n;i++)cin>>l[i]>>a[i];
    int q;
    cin>>q;
    vvi g(n+1);
    vi d(n+1,INF);
    map<int,int>cnt;
    d[1]=1;
    for(int i=1;i<=n;i++)g[a[i]].push_back(i);
    queue<int>que;
    que.push(1);
    while(!que.empty()){
        int v=que.front();que.pop();
        dbg(v);
        for(auto u:g[v])if(chmin(d[u],max(l[u],d[v])))que.push(u);
    }
    for(int i=1;i<=n;i++)cnt[d[i]]++;
    for(auto it=cnt.begin();it!=prev(cnt.end());it=next(it))next(it)->second+=it->second;
    while(q--){
        int tp;
        cin>>tp;
        if(tp==1){
            int x;
            cin>>x;
            cout<<prev(cnt.upper_bound(x))->second<<'\n';
        }
        else{
            int y;
            cin>>y;
            cout<<(d[y]==INF?-1:d[y])<<'\n';
        }
    }
}
0