Submission #417287

#TimeUsernameProblemLanguageResultExecution timeMemory
417287shenxyWorst Reporter 4 (JOI21_worst_reporter4)C++11
14 / 100
1296 ms196932 KiB
#include <cstdio> #include <algorithm> #include <vector> #include <cstring> using namespace std; int N, A[5001], H[5001]; long long C[5001], dptable[5001][5001]; vector<int> adjlist[5001]; long long dp(int v, int k) { if (dptable[v][k] != -1) return dptable[v][k]; if (H[v] >= H[k]) { long long a1 = 0, a2 = 0; if (H[v] != H[k]) a1 += C[v]; for (int i: adjlist[v]) a1 += dp(i, k), a2 += dp(i, v); return dptable[v][k] = min(a1, a2); } else { dptable[v][k] = C[v]; for (int i: adjlist[v]) dptable[v][k] += dp(i, k); return dptable[v][k]; } } int main() { memset(dptable, -1, sizeof dptable); scanf("%d", &N); for (int i = 1; i <= N; ++i) scanf("%d %d %lld", &A[i], &H[i], &C[i]); for (int i = 2; i <= N; ++i) adjlist[A[i]].push_back(i); long long bans = 1000000000000000000LL; for (int i = 1; i <= N; ++i) bans = min(bans, dp(1, i)); printf("%lld", bans); return 0; }

Compilation message (stderr)

worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
worst_reporter2.cpp:25:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  for (int i = 1; i <= N; ++i) scanf("%d %d %lld", &A[i], &H[i], &C[i]);
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...