結果

問題 No.2325 Skill Tree
ユーザー tanadaaa
提出日時 2023-05-28 15:37:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,563 bytes
コンパイル時間 2,517 ms
コンパイル使用メモリ 177,160 KB
実行使用メモリ 23,552 KB
最終ジャッジ日時 2024-12-27 07:45:59
合計ジャッジ時間 61,517 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12 WA * 13 TLE * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vs = vector<string>;
using vc = vector<char>;
using pll = pair<long long, long long>;
const int INF = 1e9;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

struct edge {
  int to;
  int cost;
  edge(int t, int w) : to(t), cost(w) { }
};

using Graph = vector<vector<edge>>;

vector<bool> seen;
int xcount = 0,lx = 0;
void dfs1(const Graph &G, int v) {
    seen[v] = true;
    for (auto e : G[v]) { 
        if (seen[e.to]) continue;
        else if(e.cost <= lx){
          dfs1(G,e.to);
          xcount++;
        }
    }
}

int ycount = -1,ly = 0;
void dfs2(const Graph &G, int v) {
    seen[v] = true;
    for (auto e : G[v]) { 
        if (seen[e.to]) continue;
        else if(e.to == ly){
          ycount = max(ycount,e.cost);
          return;
        }
      else{
        ycount = max(ycount,e.cost);
        dfs2(G,e.to);
      }
    }
}


int main() {
  int n;
  cin >> n;
  vector<vector<edge>> g(n);
  rep(i,n-1){
    int l,a;
    cin >> l >> a;
    a--;
    g[a].push_back(edge(i+1,l));
  }
  
  int q;
  cin >> q;
  rep(iii,q){
    int t,x;
    cin >> t >> x;
    if(t == 1){
      seen.assign(n, false);
      xcount = 0;
      lx = x;
      dfs1(g,0);
      cout << xcount+1 << endl;
    }
    else{
      seen.assign(n, false);
      ycount = -1;
      x--;
      ly = x;
      dfs2(g,0);
      cout << ycount << endl;
    }
  }
  
}
0