Submission #841105

#TimeUsernameProblemLanguageResultExecution timeMemory
841105danikoynovClosing Time (IOI23_closing)C++17
9 / 100
48 ms10032 KiB
#include "closing.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 3e3 + 10; vector < pair < int, ll > > adj[maxn]; ll dist[2][maxn]; int n; void bfs(int s, ll arr[]) { queue < int > q; for (int i = 0; i < n; i ++) arr[i] = -1; arr[s] = 0; q.push(s); while(!q.empty()) { int v = q.front(); q.pop(); for (pair < int, ll > nb : adj[v]) { if (arr[nb.first] == -1) { arr[nb.first] = arr[v] + nb.second; q.push(nb.first); } } } } const ll inf = 1e18; ll value[maxn]; ll dp[maxn][maxn], sub[maxn], temp[maxn]; void dfs(int v, int par) { sub[v] = 1; for (pair < int, ll > nb : adj[v]) { if (nb.first == par) continue; dfs(nb.first, v); } dp[v][0] = 0; dp[v][1] = max((ll)(0), dist[1][v] - value[v]); for (pair < int, ll > nb : adj[v]) { if (nb.first == par) continue; int u = nb.first; for (int i = 0; i <= sub[u] + sub[v]; i ++) temp[i] = inf; for (int i = 0; i <= sub[v]; i ++) for (int j = 0; j <= sub[u]; j ++) { if (i == 0 && j > 0) continue; temp[i + j] = min(temp[i + j], dp[v][i] + dp[u][j]); } for (int i = 0; i <= sub[v] + sub[u]; i ++) dp[v][i] = temp[i]; sub[v] += sub[u]; } } int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W) { for (int i = 0; i < N; i ++) { dist[0][i] = dist[1][i] = 0; adj[i].clear(); value[i] = 0; } n = N; for (int i = 0; i < N - 1; i ++) { adj[U[i]].push_back({V[i], W[i]}); adj[V[i]].push_back({U[i], W[i]}); } bfs(X, dist[0]); bfs(Y, dist[1]); vector < pair < ll, int > > ord; ll left_k = K; for (int i = 0; i < N; i ++) { ord.push_back({dist[0][i], i}); } sort(ord.begin(), ord.end()); ///for (int i = 0; i < ord.size(); i ++) /// cout << "here " << ord[i].first << " " << ord[i].second << endl; ll ans = 0; for (int i = 0; i < ord.size(); i ++) { left_k = left_k - ord[i].first; if (left_k < 0) break; value[ord[i].second] = ord[i].first; dfs(Y, -1); /**cout << "step " << i + 1 << " " << left_k << endl; for (int j = 0; j <= N; j ++) cout << dp[Y][j] << " "; cout << endl;*/ ll cur = 0; int j = 0; while(j <= n && dp[Y][j] <= left_k) j ++; j --; cur = i + 1 + j; if (cur > ans) ans = cur; } return ans; }

Compilation message (stderr)

closing.cpp: In function 'void dfs(int, int)':
closing.cpp:55:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   55 |         if (nb.first == par)
      |         ^~
closing.cpp:57:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   57 |             int u = nb.first;
      |             ^~~
closing.cpp:58:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   58 |         for (int i = 0; i <= sub[u] + sub[v]; i ++)
      |         ^~~
closing.cpp:61:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   61 |             for (int i = 0; i <= sub[v]; i ++)
      |             ^~~
closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:105:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |     for (int i = 0; i < ord.size(); i ++)
      |                     ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...