Submission #740934

#TimeUsernameProblemLanguageResultExecution timeMemory
740934nguyentunglamRoad Closures (APIO21_roads)C++17
0 / 100
2053 ms20672 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 1e5 + 10; long long f[N], g[N]; vector<pair<int, int> > adj[N]; int k; void dfs(int u, int par = 0) { long long sum = 0; f[u] = g[u] = 0; vector<long long> lst; for(auto &[v, w] : adj[u]) if (v != par) { dfs(v, u); sum += g[v] + w; lst.push_back(f[v] - g[v] - w); } sort(lst.begin(), lst.end()); for(int i = 0; i < min(k - 1, (int)lst.size()); i++) sum += lst[i]; f[u] = sum; if (k - 1 < lst.size()) sum += lst[k - 1]; g[u] = min(sum, f[u]); // cout << u << " " << f[u] << " " << g[u] << endl; } vector<long long> minimum_closure_costs (int n, vector<int> u, vector<int> v, vector<int> w) { for(int i = 0; i < n - 1; i++) { adj[u[i]].emplace_back(v[i], w[i]); adj[v[i]].emplace_back(u[i], w[i]); } vector<long long> ret(n); for(k = 0; k < n; k++) { dfs(0); ret[k] = min(f[0], g[0]); } return ret; } #ifdef ngu int main() { if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } // minimum_closure_costs(4, [0, 2, 0], [1, 0, 3], [5, 10, 5]); // int n; cin >> n; // vector<int> u(n), v(n), w(n); // for(int i = 0; i < n; i++) cin >> u[i] >> v[i] >> w[i]; // vector<long long> res = minimum_closure_costs(n, u, v, w); } #endif // ngu

Compilation message (stderr)

roads.cpp: In function 'void dfs(int, int)':
roads.cpp:23:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     if (k - 1 < lst.size()) sum += lst[k - 1];
      |         ~~~~~~^~~~~~~~~~~~
#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...