# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
876428 |
2023-11-21T18:07:23 Z |
Mr_Ph |
Paths (RMI21_paths) |
C++17 |
|
173 ms |
17744 KB |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
using namespace std;
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
ll mod=(ll)1e9+7;
ll mod1=998244353;
///the defines :)
#define endl '\n'
#define vi vector<int>
#define vll vector<ll>
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
#define int long long
vector<vector<pair<int,int>>>adj;
int length[20002];
pair<int,int>dfs(int node,int parent,int w)
{
// cout<<"HI"<<endl;
pair<int,int>xd={0,0};
for(auto i:adj[node])
{
if(i.first==parent)
continue;
pair<int,int>mx=dfs(i.first,node,i.second);
mx.first+=w;
xd=max(xd,mx);
}
if(adj[node].sz==1)
{
length[node]=w;
return {w,node};
}
length[xd.second]+=w;
return xd;
}
void preprocess() {}
void solve()
{
int n,k;
cin>>n>>k;
adj.resize(n+1);
for(int i=0;i<n-1;i++)
{
int a,b,c;
cin>>a>>b>>c;
adj[a].push_back({b,c});
adj[b].push_back({a,c});
}
for(int i=1;i<=n;i++)
{
//cout<<i<<endl;
for(int j=1;j<=n;j++)length[j]=0;
dfs(i,0,0);
vi xd;
for(int j=1;j<=n;j++)xd.push_back(length[j]);
sort(allr(xd));
int ans=0;
for(int j=0;j<min((int)xd.sz,k);j++)
ans+=xd[j];
cout<<ans<<endl;
}
}
signed main()
{
// freopen("meta_game_input.txt","r",stdin);
// freopen("otput.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
preprocess();
//bla();
int t=1;
//cin>>t;
while(t--)
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
352 KB |
Output is correct |
8 |
Correct |
35 ms |
568 KB |
Output is correct |
9 |
Correct |
23 ms |
604 KB |
Output is correct |
10 |
Correct |
18 ms |
600 KB |
Output is correct |
11 |
Correct |
29 ms |
580 KB |
Output is correct |
12 |
Correct |
20 ms |
356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
352 KB |
Output is correct |
8 |
Correct |
35 ms |
568 KB |
Output is correct |
9 |
Correct |
23 ms |
604 KB |
Output is correct |
10 |
Correct |
18 ms |
600 KB |
Output is correct |
11 |
Correct |
29 ms |
580 KB |
Output is correct |
12 |
Correct |
20 ms |
356 KB |
Output is correct |
13 |
Correct |
161 ms |
688 KB |
Output is correct |
14 |
Correct |
137 ms |
784 KB |
Output is correct |
15 |
Correct |
76 ms |
604 KB |
Output is correct |
16 |
Correct |
164 ms |
604 KB |
Output is correct |
17 |
Correct |
102 ms |
692 KB |
Output is correct |
18 |
Correct |
85 ms |
600 KB |
Output is correct |
19 |
Correct |
173 ms |
708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
35 ms |
17744 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
352 KB |
Output is correct |
8 |
Correct |
35 ms |
568 KB |
Output is correct |
9 |
Correct |
23 ms |
604 KB |
Output is correct |
10 |
Correct |
18 ms |
600 KB |
Output is correct |
11 |
Correct |
29 ms |
580 KB |
Output is correct |
12 |
Correct |
20 ms |
356 KB |
Output is correct |
13 |
Correct |
161 ms |
688 KB |
Output is correct |
14 |
Correct |
137 ms |
784 KB |
Output is correct |
15 |
Correct |
76 ms |
604 KB |
Output is correct |
16 |
Correct |
164 ms |
604 KB |
Output is correct |
17 |
Correct |
102 ms |
692 KB |
Output is correct |
18 |
Correct |
85 ms |
600 KB |
Output is correct |
19 |
Correct |
173 ms |
708 KB |
Output is correct |
20 |
Runtime error |
35 ms |
17744 KB |
Execution killed with signal 11 |
21 |
Halted |
0 ms |
0 KB |
- |