# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
703173 |
2023-02-26T10:40:50 Z |
Nursik |
Paths (RMI21_paths) |
C++14 |
|
600 ms |
31048 KB |
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <functional>
#include <complex>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
const ll maxn = 1e6 + 10, maxm = 3e5 + 1;
const ll mod = 1e9 + 7, cmod = 998244353, inf = 1e9, blcok = 400, p2 = 31;
const ld eps = 1e-9;
int n, k;
ll dp[maxn];
vector<pair<int, int>> g[maxn];
vector<ll> vec;
void dfs(int v, int p = 0){
dp[v] = 0;
for (auto to : g[v]){
int go = to.f, w = to.s;
if (go != p){
dfs(go, v);
dp[v] = max(dp[v], dp[go] + w);
}
}
int is = 0;
for (auto to : g[v]){
int go = to.f, w = to.s;
if (go != p){
if (dp[v] != dp[go] + w || is){
vec.pb(dp[go] + w);
}
else{
is = 1;
}
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int u, v, c, i = 1; i < n; ++i){
cin >> u >> v >> c;
g[u].pb(mp(v, c));
g[v].pb(mp(u, c));
}
for (int i = 1; i <= n; ++i){
dfs(i);
sort(vec.begin(), vec.end());
reverse(vec.begin(), vec.end());
ll ans = dp[i];
//cout << ans << '\n';
for (int i = 0; i < k - 1; ++i){
ans += vec[i];
// cout << vec[i] << " ";
}
cout << ans << " ";
vec.clear();
// exit(0);
}
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23812 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23740 KB |
Output is correct |
5 |
Correct |
13 ms |
23780 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
15 ms |
23820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23812 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23740 KB |
Output is correct |
5 |
Correct |
13 ms |
23780 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
15 ms |
23820 KB |
Output is correct |
8 |
Correct |
51 ms |
23824 KB |
Output is correct |
9 |
Correct |
44 ms |
23936 KB |
Output is correct |
10 |
Correct |
34 ms |
23880 KB |
Output is correct |
11 |
Correct |
51 ms |
23892 KB |
Output is correct |
12 |
Correct |
37 ms |
23888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23812 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23740 KB |
Output is correct |
5 |
Correct |
13 ms |
23780 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
15 ms |
23820 KB |
Output is correct |
8 |
Correct |
51 ms |
23824 KB |
Output is correct |
9 |
Correct |
44 ms |
23936 KB |
Output is correct |
10 |
Correct |
34 ms |
23880 KB |
Output is correct |
11 |
Correct |
51 ms |
23892 KB |
Output is correct |
12 |
Correct |
37 ms |
23888 KB |
Output is correct |
13 |
Correct |
188 ms |
24032 KB |
Output is correct |
14 |
Correct |
167 ms |
24148 KB |
Output is correct |
15 |
Correct |
106 ms |
23984 KB |
Output is correct |
16 |
Correct |
188 ms |
24100 KB |
Output is correct |
17 |
Correct |
131 ms |
23936 KB |
Output is correct |
18 |
Correct |
109 ms |
23884 KB |
Output is correct |
19 |
Correct |
183 ms |
23960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1069 ms |
31048 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23812 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23740 KB |
Output is correct |
5 |
Correct |
13 ms |
23780 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
15 ms |
23820 KB |
Output is correct |
8 |
Correct |
51 ms |
23824 KB |
Output is correct |
9 |
Correct |
44 ms |
23936 KB |
Output is correct |
10 |
Correct |
34 ms |
23880 KB |
Output is correct |
11 |
Correct |
51 ms |
23892 KB |
Output is correct |
12 |
Correct |
37 ms |
23888 KB |
Output is correct |
13 |
Correct |
188 ms |
24032 KB |
Output is correct |
14 |
Correct |
167 ms |
24148 KB |
Output is correct |
15 |
Correct |
106 ms |
23984 KB |
Output is correct |
16 |
Correct |
188 ms |
24100 KB |
Output is correct |
17 |
Correct |
131 ms |
23936 KB |
Output is correct |
18 |
Correct |
109 ms |
23884 KB |
Output is correct |
19 |
Correct |
183 ms |
23960 KB |
Output is correct |
20 |
Execution timed out |
1069 ms |
31048 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |