이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include "roads.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
ll n;
vector<vector<pair<ll,ll>>> cad;
ll k;
ll sol(ll node,ll B, ll P)
{
if(B>k) return 1e14;
vector<pair<ll,ll>> asd;
for(auto i:cad[node])
{
if(i.x==P) continue;
asd.push_back({sol(i.x,1,node),i.y+sol(i.x,0,node)});
}
if(asd.size()==0) return 0;
vector<ll> dp(asd.size()+1,1e14);
vector<ll> dp2=dp;
dp[0]=0;
for(int i=0; i<asd.size(); i++)
{
for(int j=dp.size()-1; j>-1; j--)
{
dp2[j]=dp[j]+asd[i].y,dp[j];
if(j>0) dp2[j]=min(dp[j-1]+asd[i].x,dp2[j]);
}
swap(dp,dp2);
}
if(k-B>=dp.size()) return dp.back();
return dp[k-B];
}
std::vector<long long> minimum_closure_costs(int N, std::vector<int> U,std::vector<int> V,std::vector<int> W) {
n=N;
cad.resize(n+1);
for(int i=0; i<n-1; i++)
{
cad[U[i]].push_back({V[i],W[i]});
cad[V[i]].push_back({U[i],W[i]});
}
vector<ll> s(n,0);
for(int i=0; i<n; i++)
{
k=i;
s[i]=sol(0,0,-1);
}
return s;
}
컴파일 시 표준 에러 (stderr) 메시지
roads.cpp: In function 'll sol(ll, ll, ll)':
roads.cpp:23:19: 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]
23 | for(int i=0; i<asd.size(); i++)
| ~^~~~~~~~~~~
roads.cpp:32:11: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | if(k-B>=dp.size()) return dp.back();
| ~~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |