제출 #340153

#제출 시각아이디문제언어결과실행 시간메모리
340153tengiz05바이오칩 (IZhO12_biochips)C++17
100 / 100
395 ms403372 KiB
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() typedef long long ll; using namespace std; template<class T> bool chmin(T& a, const T& b){return a>b?a=b,true:false;} template<class T> bool chmax(T& a, const T& b){return a<b?a=b,true:false;} const int N = 2e5+5, M = 505; const int inf = 1e9; int n, m; int dp[N][M], w[N]; vector<int> edges[N]; int timer = 1; int v[N], l[N]; void dfs(int u){ int tmp = timer; for(auto v : edges[u]) dfs(v); v[timer] = w[u]; l[timer] = tmp; timer++; } void Solve(){ cin >> n >> m; int root; for(int i=1;i<=n;i++){ int j, cost; cin >> j >> cost; if(j > 0)edges[j].push_back(i); else root = i; w[i] = cost; } dfs(root); for(int i=0;i<=n;i++){ for(int j=1;j<=m;j++){ dp[i][j] = -inf; } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ dp[i][j] = max(dp[i-1][j], dp[l[i]-1][j-1]+v[i]); } } cout << dp[n][m] << '\n'; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(); int t=1; while(t--)Solve(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

biochips.cpp: In function 'void Solve()':
biochips.cpp:32:6: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |   dfs(root);
      |   ~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...