Submission #462508

#TimeUsernameProblemLanguageResultExecution timeMemory
462508SamAndBiochips (IZhO12_biochips)C++17
100 / 100
615 ms412556 KiB
#include <bits/stdc++.h> using namespace std; #define m_p make_pair #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define fi first #define se second typedef long long ll; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnf(2106); const int N = 200005, M = 503, INF = 1000000009; int n, m; int a[N]; vector<int> g[N]; int tin[N], tout[N], ti; void dfs(int x) { tin[x] = ++ti; for (int i = 0; i < g[x].size(); ++i) { int h = g[x][i]; dfs(h); } tout[x] = ti; } vector<pair<int, int> > v[N]; int dp[N][M]; void solv() { cin >> n >> m; for (int x = 1; x <= n; ++x) { int p; cin >> p; g[p].push_back(x); cin >> a[x]; } dfs(g[0][0]); for (int x = 1; x <= n; ++x) v[tout[x]].push_back(m_p(tin[x], a[x])); for (int i = 0; i <= n; ++i) { for (int j = 0; j <= m; ++j) { dp[i][j] = -INF; } dp[i][0] = 0; } for (int i = 1; i <= n; ++i) { for (int q = 1; q <= m; ++q) { for (int j = 0; j < sz(v[i]); ++j) { dp[i][q] = max(dp[i][q], dp[v[i][j].fi - 1][q - 1] + v[i][j].se); } dp[i + 1][q] = max(dp[i + 1][q], dp[i][q]); } } cout << dp[n][m] << "\n"; } int main() { #ifdef SOMETHING freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif // SOMETHING ios_base::sync_with_stdio(false), cin.tie(0); int tt = 1; //cin >> tt; while (tt--) { solv(); } return 0; }

Compilation message (stderr)

biochips.cpp: In function 'void dfs(int)':
biochips.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i = 0; i < g[x].size(); ++i)
      |                     ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...