Submission #426269

#TimeUsernameProblemLanguageResultExecution timeMemory
426269OzyRoad Closures (APIO21_roads)C++17
0 / 100
379 ms31888 KiB
#include "roads.h" #include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for (int i = (a); i <= (b); i++) #define repa(i,a,b) for (int i = (a); i >= (b); i--) #define lli long long int #define debugsl(a) cout << #a << " = " << a << ", " #define debug(a) cout << #a << " = " << a << endl #define MAX 2000 #define des first #define peso second vector< pair<lli,lli> > hijos[MAX+2]; lli dp[MAX+2][MAX+2]; lli total; void DFS(lli pos, lli padre, lli k) { vector<pair < lli , pair<lli,lli> > > costos; for (auto h : hijos[pos]) { if (h.des == padre) continue; DFS(h.des, pos, k); costos.push_back({dp[k][h.des] + h.peso - dp[k-1][h.des], {h.des, h.peso}}); } sort(costos.begin(), costos.end()); lli cont = 0; for (auto act : costos) { if (cont+k < costos.size()) { dp[k][pos] += dp[k][act.second.first] + act.second.second; cont++; } else dp[k][pos] += dp[k-1][act.second.first]; } dp[k][pos] = min(dp[k][pos], dp[k-1][pos]); } void inicial(lli pos, lli padre) { for(auto h : hijos[pos]) { if (h.des == padre) continue; inicial(h.des,pos); dp[0][pos] += dp[0][h.des] + h.peso; } } std::vector <long long> minimum_closure_costs(int N, std::vector<int> U, std::vector<int> V, std::vector<int> W) { vector<long long> res (N, 0); total = 0; rep(i,0,N-2) { hijos[ U[i] ].push_back({V[i], W[i]}); hijos[ V[i] ].push_back({U[i], W[i]}); total += W[i]; } inicial(0,-1); rep(i,1,N-1) DFS(0,-1,i); rep(i,0,N-1) res[i] = dp[i][0]; return res; }

Compilation message (stderr)

roads.cpp: In function 'void DFS(long long int, long long int, long long int)':
roads.cpp:32:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         if (cont+k < costos.size()) {
      |             ~~~~~~~^~~~~~~~~~~~~~~
#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...