답안 #477985

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477985 2021-10-05T00:42:48 Z zerver Magic Tree (CEOI19_magictree) C++14
16 / 100
142 ms 29220 KB
#include <bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(0); cin.tie(nullptr)
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define sz(v) int(v.size())
#define ss second
#define ff first
#define endl '\n'
using namespace std;
typedef long long Long;
typedef pair<int, int> ii;
const Long INF = 1e13;
const int N = 1e5 + 7;
vector<int> adj[N];
set<ii> dif[N];
int dia[N], peso[N], pt[N];

void dfs(int from){
  int big = 0;
  for(int to: adj[from]){
    dfs(to);
    if(big == 0 || sz(dif[pt[to]]) > sz(dif[pt[big]])) big = to;
  }
  if(big == 0){
    if(dia[from] == 0) return;
    dif[pt[from]].insert({dia[from], peso[from]});
    return;
  }
  pt[from] = pt[big];
  for(int to: adj[from]){
    if(to == big) continue;
    for(auto p: dif[pt[to]]) dif[pt[from]].insert(p);
  }
  if(dia[from] != 0){
    ii par = {dia[from] + 1, 0};
    auto it = dif[pt[from]].lower_bound(par);
    ii ins = {dia[from], peso[from]};
    ii gua = ins;
    for(; it != dif[pt[from]].end(); ){
      ii npar = *(it);
      if(npar.ss <= ins.ss){
        ins.ss -= npar.ss;
        it = dif[pt[from]].erase(it);
      }
      else{
        npar.ss -= ins.ss;
        dif[pt[from]].erase(it);
        dif[pt[from]].insert(npar);
        break;
      }
    }
    dif[pt[from]].insert(gua);
  }
}

void solve(){
  int n, m, k; cin >> n >> m >> k;
  for(int i = 2; i <= n; i++){
    int p; cin >> p;
    adj[p].push_back(i);
  }
  for(int i = 0; i < m; i++){
    int v; cin >> v;
    cin >> dia[v] >> peso[v];
  }
  for(int i = 1; i <= n; i++) pt[i] = i;
  dfs(1);
  Long ans = 0;
  for(auto p: dif[pt[1]]) ans += p.ss;
  cout << ans << endl;
}

int main(){
  FAST_IO;
  int tt = 1; 
  // cin >> tt;
  while(tt--) solve();
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 7244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 15808 KB Output is correct
2 Correct 45 ms 17732 KB Output is correct
3 Correct 139 ms 29220 KB Output is correct
4 Correct 96 ms 17348 KB Output is correct
5 Correct 126 ms 18884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 7500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 142 ms 27648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 7244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 8012 KB Output is correct
2 Correct 31 ms 10748 KB Output is correct
3 Correct 34 ms 10808 KB Output is correct
4 Correct 31 ms 10824 KB Output is correct
5 Correct 13 ms 9292 KB Output is correct
6 Correct 31 ms 13048 KB Output is correct
7 Correct 39 ms 16544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 7244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 7244 KB Output isn't correct
2 Halted 0 ms 0 KB -