Submission #979919

#TimeUsernameProblemLanguageResultExecution timeMemory
979919nninRoad Closures (APIO21_roads)C++14
7 / 100
35 ms9420 KiB
#include "roads.h" #include<bits/stdc++.h> #define pii pair<int,int> #define f first #define s second using namespace std; using ll = long long; bool done[100005]; int ct[100005]; vector<int> deg[100005]; ll dp[100005]; 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++) { ct[U[i]]++; ct[V[i]]++; } for(int i=0;i<n;i++) { deg[ct[i]].push_back(i); } vector<long long> ans(n, 0); ll total = 0; dp[0] = 0; for(int i=1;i<n;i++) { total += W[i-1]; if(i>=1) dp[i] = dp[i-1]+W[i-1]; if(i>=2) dp[i] = min(dp[i], dp[i-2]+W[i-1]); } ans[1] = min(dp[n-1], dp[n-2]); ans[0] = total; return ans; }
#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...