# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
642783 |
2022-09-20T13:28:55 Z |
Tenis0206 |
Paths (RMI21_paths) |
C++11 |
|
600 ms |
18900 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,k;
int Max[100005],d[100005];
vector<pair<int,int>> Gaux[100005];
vector<int> G[100005];
int l[100005];
vector<int> v;
void debug(vector<int> c)
{
for(auto it : c)
{
cerr<<it<<' ';
}
cerr<<'\n';
}
void Add(int val)
{
v.push_back(val);
}
int kmax()
{
int sum = 0;
sort(v.begin(),v.end(),greater<int>());
// debug(v);
for(int i=0;i<k && i<v.size();i++)
{
sum += v[i];
}
return sum;
}
void preset(int nod, int dad = 0)
{
for(auto it : Gaux[nod])
{
if(it.first==dad)
{
continue;
}
preset(it.first,nod);
d[it.first] = it.second;
}
}
void dfs(int nod, int dad = 0)
{
for(auto it : G[nod])
{
if(it==dad)
{
continue;
}
dfs(it,nod);
if(l[it] + d[it] > l[Max[nod]] + d[Max[nod]])
{
Max[nod] = it;
}
}
l[nod] = l[Max[nod]] + d[Max[nod]];
for(auto it : G[nod])
{
if(it==dad || it==Max[nod])
{
continue;
}
Add(l[it] + d[it]);
}
}
signed main()
{
cin>>n>>k;
for(int i=1; i<n; i++)
{
int x,y,c;
cin>>x>>y>>c;
Gaux[x].push_back({y,c});
Gaux[y].push_back({x,c});
G[x].push_back(y);
G[y].push_back(x);
}
for(int i=1; i<=n; i++)
{
v.clear();
for(int j=1;j<=n;j++)
{
Max[j] = 0, d[j] = 0, l[j] = 0;
}
preset(i);
dfs(i);
Add(l[i]);
cout<<kmax()<<'\n';
}
return 0;
}
Compilation message
Main.cpp: In function 'long long int kmax()':
Main.cpp:36:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i=0;i<k && i<v.size();i++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
5 ms |
4956 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
6 ms |
5012 KB |
Output is correct |
6 |
Correct |
4 ms |
5012 KB |
Output is correct |
7 |
Correct |
5 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
5 ms |
4956 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
6 ms |
5012 KB |
Output is correct |
6 |
Correct |
4 ms |
5012 KB |
Output is correct |
7 |
Correct |
5 ms |
4948 KB |
Output is correct |
8 |
Correct |
65 ms |
5156 KB |
Output is correct |
9 |
Correct |
71 ms |
5208 KB |
Output is correct |
10 |
Correct |
50 ms |
5076 KB |
Output is correct |
11 |
Correct |
60 ms |
5144 KB |
Output is correct |
12 |
Correct |
52 ms |
5152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
5 ms |
4956 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
6 ms |
5012 KB |
Output is correct |
6 |
Correct |
4 ms |
5012 KB |
Output is correct |
7 |
Correct |
5 ms |
4948 KB |
Output is correct |
8 |
Correct |
65 ms |
5156 KB |
Output is correct |
9 |
Correct |
71 ms |
5208 KB |
Output is correct |
10 |
Correct |
50 ms |
5076 KB |
Output is correct |
11 |
Correct |
60 ms |
5144 KB |
Output is correct |
12 |
Correct |
52 ms |
5152 KB |
Output is correct |
13 |
Correct |
292 ms |
5324 KB |
Output is correct |
14 |
Correct |
276 ms |
5384 KB |
Output is correct |
15 |
Correct |
195 ms |
5324 KB |
Output is correct |
16 |
Correct |
264 ms |
5292 KB |
Output is correct |
17 |
Correct |
243 ms |
5276 KB |
Output is correct |
18 |
Correct |
167 ms |
5244 KB |
Output is correct |
19 |
Correct |
303 ms |
5416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1075 ms |
18900 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
5 ms |
4956 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
6 ms |
5012 KB |
Output is correct |
6 |
Correct |
4 ms |
5012 KB |
Output is correct |
7 |
Correct |
5 ms |
4948 KB |
Output is correct |
8 |
Correct |
65 ms |
5156 KB |
Output is correct |
9 |
Correct |
71 ms |
5208 KB |
Output is correct |
10 |
Correct |
50 ms |
5076 KB |
Output is correct |
11 |
Correct |
60 ms |
5144 KB |
Output is correct |
12 |
Correct |
52 ms |
5152 KB |
Output is correct |
13 |
Correct |
292 ms |
5324 KB |
Output is correct |
14 |
Correct |
276 ms |
5384 KB |
Output is correct |
15 |
Correct |
195 ms |
5324 KB |
Output is correct |
16 |
Correct |
264 ms |
5292 KB |
Output is correct |
17 |
Correct |
243 ms |
5276 KB |
Output is correct |
18 |
Correct |
167 ms |
5244 KB |
Output is correct |
19 |
Correct |
303 ms |
5416 KB |
Output is correct |
20 |
Execution timed out |
1075 ms |
18900 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |