#include <bits/stdc++.h>
using namespace std;
const long long max_size = 2e3 + 1;
vector <pair <long long, long long>> mc[max_size];
long long dog[max_size], d[max_size], dp[max_size];
pair <long long, long long> t[max_size];
void dfs (long long nod, long long par)
{
t[nod].first = par;
for (auto f : mc[nod])
{
if (f.first == par)
{
continue;
}
t[f.first].second = f.second;
dp[f.first] = dp[nod] + d[f.second];
dfs(f.first, nod);
}
}
signed main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, k;
cin >> n >> k;
for (long long i = 1; i < n; i++)
{
long long x, y, c;
cin >> x >> y >> c;
dog[i] = c;
mc[x].push_back({y, i});
mc[y].push_back({x, i});
}
for (long long i = 1; i <= n; i++)
{
for (long long j = 1; j < n; j++)
{
d[j] = dog[j];
}
long long ans = 0;
for (long long j = 1; j <= k; j++)
{
dp[i] = 0;
dfs(i, 0);
long long idx = 0, mx = -1;
for (long long tt = 1; tt <= n; tt++)
{
// cout << j << " " << dp[tt] << '\n';
if (dp[tt] > mx)
{
mx = dp[tt];
idx = tt;
}
}
// cout << '\n';
ans += mx;
long long nod = idx;
while (t[nod].first != 0)
{
d[t[nod].second] = 0;
nod = t[nod].first;
}
}
cout << ans;
if (i < n)
{
cout << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Execution timed out |
739 ms |
620 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Execution timed out |
739 ms |
620 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Execution timed out |
739 ms |
620 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |