#include "roads.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ii> vi;
typedef pair<ii,ll> iii;
const ll MAX=1e16;
const int MAX_N=2e3+10;
bool vis[MAX_N];
vector<vi> G;
int n,ti;
bool orden(ii a,ii b){
return -a.first+a.second<-b.first+b.second;
}
ll dp[MAX_N][MAX_N];
ll knap(int u,int p,int k){
if(dp[u][k]!=-1) return dp[u][k];
vector<ii> op;
ll s=0;
for(auto &v:G[u]){
if(v.first!=p){
if(k>=1){
op.push_back(ii(knap(v.first,u,k)+v.second,knap(v.first,u,k-1)));
}
s+=knap(v.first,u,k)+v.second;
}
}
sort(op.begin(),op.end(),orden);
int c=0;
for(int i=0;i<op.size();i++){
if(i<k) s+=(-op[i].first+op[i].second);
}
return dp[u][k]=s;
}
std::vector<long long> minimum_closure_costs(int N, std::vector<int> U,
std::vector<int> V,
std::vector<int> W) {
n=N;
vector<ll> res;
//vector<iii> ed;
G.resize(n+1);
for(int i=0;i<n-1;i++){
int a=U[i],b=V[i],w=W[i];
G[a].push_back(ii(b,w));
G[b].push_back(ii(a,w));
//ed.push_back(iii(ii(a,b),w));
}
for(int i=0;i<n;i++){
ti=i;
memset(dp,-1,sizeof dp);
res.push_back(knap(0,0,i));
}
return res;
}
Compilation message
roads.cpp: In function 'll knap(int, int, int)':
roads.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i=0;i<op.size();i++){
| ~^~~~~~~~~~
roads.cpp:30:7: warning: unused variable 'c' [-Wunused-variable]
30 | int c=0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
31820 KB |
Output is correct |
2 |
Execution timed out |
2050 ms |
32184 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
31816 KB |
Output is correct |
2 |
Execution timed out |
2064 ms |
41712 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
31860 KB |
Output is correct |
2 |
Correct |
29 ms |
31820 KB |
Output is correct |
3 |
Correct |
23 ms |
31908 KB |
Output is correct |
4 |
Incorrect |
537 ms |
31924 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
31860 KB |
Output is correct |
2 |
Correct |
29 ms |
31820 KB |
Output is correct |
3 |
Correct |
23 ms |
31908 KB |
Output is correct |
4 |
Incorrect |
537 ms |
31924 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
88 ms |
85444 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
88 ms |
85444 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
31820 KB |
Output is correct |
2 |
Execution timed out |
2050 ms |
32184 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |