Submission #417237

#TimeUsernameProblemLanguageResultExecution timeMemory
417237lycWorst Reporter 4 (JOI21_worst_reporter4)C++14
14 / 100
115 ms118212 KiB
#include <bits/stdc++.h> using namespace std; #define TRACE(x) cerr << #x << " :: " << x << endl #define _ << " " << #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(),(x).end() #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define RFOR(i,a,b) for(int i=(a);i>=(b);--i) typedef long long ll; //const int mxN = 2e5+5; const int mxN = 5e3+5; const ll inf = 1e18; int N, A[mxN], H[mxN], C[mxN]; vector<int> al[mxN]; ll dp[mxN][mxN]; void dfs(int u) { FOR(x,0,u) dp[u][x] = H[x] == H[u] ? 0 : C[u]; for (int v : al[u]) { dfs(v); FOR(x,0,u){ dp[u][x] += min(dp[v][x], H[x] <= H[v] ? dp[v][v] : inf); } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N; FOR(i,1,N){ cin >> A[i] >> H[i] >> C[i]; if (i != 1) al[A[i]].push_back(i); } H[0] = 1; dfs(1); cout << min(dp[1][0], dp[1][1]) << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...