#include "roads.h"
#include<bits/stdc++.h>
#define F first
#define S second
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
ll n,dp[2009][2],k;
vector<vector<pair<ll,ll> > >v;
vector<ll>ans;
void dfs(ll d,ll p)
{
dp[d][0]=dp[d][1]=0;
vector<pair<ll,ll> >op;
for(auto z:v[d])
if(z.F!=p)
{
dfs(z.F,d);
dp[z.F][0]+=z.S;
op.push_back({dp[z.F][1]-dp[z.F][0],z.F});
}
sort(all(op));
ll o=min((ll)op.size(),k);
for(ll i=0; i<o; i++)
dp[d][0]+=dp[op[i].S][1];
for(ll i=o; i<(ll)op.size(); i++)
dp[d][0]+=dp[op[i].S][0];
o=min((ll)op.size(),k-1);
for(ll i=0; i<o; i++)
dp[d][1]+=dp[op[i].S][1];
for(ll i=o; i<(ll)op.size(); i++)
dp[d][1]+=dp[op[i].S][0];
}
vector<ll>minimum_closure_costs(int N,vector<int> U,vector<int> V,vector<int> W)
{
n=N;
v.resize(n);
ans.resize(n,0);
for(ll i=0; i<n-1; i++)
{
v[U[i]].push_back({V[i],W[i]});
v[V[i]].push_back({U[i],W[i]});
ans[0]+=W[i];
}
for(k=1; k<n; k++)
{
dfs(0,-1);
ans[k]=min(dp[0][0],dp[0][1]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
206 ms |
560 KB |
Output is correct |
3 |
Correct |
228 ms |
568 KB |
Output is correct |
4 |
Correct |
280 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
192 ms |
540 KB |
Output is correct |
9 |
Correct |
329 ms |
568 KB |
Output is correct |
10 |
Correct |
3 ms |
204 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Runtime error |
32 ms |
12760 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Runtime error |
37 ms |
18400 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
47 ms |
21512 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
47 ms |
21512 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
206 ms |
560 KB |
Output is correct |
3 |
Correct |
228 ms |
568 KB |
Output is correct |
4 |
Correct |
280 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
192 ms |
540 KB |
Output is correct |
9 |
Correct |
329 ms |
568 KB |
Output is correct |
10 |
Correct |
3 ms |
204 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Runtime error |
32 ms |
12760 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |