# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
498658 |
2021-12-26T04:44:50 Z |
model_code |
Paths (RMI21_paths) |
C++17 |
|
221 ms |
604 KB |
// paths_subtask4_alexandra.cpp
//N^2 logN
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#define DIM 2005
using namespace std;
int n, k, i, j, nr, x, y, c;
long long lantMax[DIM], lanturi[DIM], sum;
vector< pair<int, int> > v[DIM];
void dfs(int nod, int t) {
for (int i = 0; i < v[nod].size(); i++) {
int fiu = v[nod][i].first;
if (fiu == t) {
continue;
}
dfs(fiu, nod);
lantMax[nod] = max(lantMax[nod], lantMax[fiu] + v[nod][i].second);
}
bool ok = false;
for (int i = 0; i < v[nod].size(); i++) {
int fiu = v[nod][i].first;
if (fiu == t) {
continue;
}
if (lantMax[nod] != lantMax[fiu] + v[nod][i].second || ok) {
lanturi[++nr] = lantMax[fiu] + v[nod][i].second;
}
else {
ok = true;
}
}
}
int main() {
cin>> n >> k;
for (i = 1; i < n; i++) {
cin>> x >> y >> c;
v[x].push_back(make_pair(y, c));
v[y].push_back(make_pair(x, c));
}
for (i = 1; i <= n; i++) {
nr = 0;
memset(lantMax, 0, sizeof(lantMax));
dfs(i, 0);
lanturi[++nr] = lantMax[i];
sum = 0;
sort(lanturi + 1, lanturi + nr + 1);
for (j = nr; j >= nr - k + 1; j--) {
sum += lanturi[j];
}
cout<< sum <<"\n";
}
}
Compilation message
Main.cpp: In function 'void dfs(int, int)':
Main.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for (int i = 0; i < v[nod].size(); i++) {
| ~~^~~~~~~~~~~~~~~
Main.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int i = 0; i < v[nod].size(); i++) {
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
42 ms |
404 KB |
Output is correct |
9 |
Correct |
48 ms |
352 KB |
Output is correct |
10 |
Correct |
36 ms |
420 KB |
Output is correct |
11 |
Correct |
60 ms |
404 KB |
Output is correct |
12 |
Correct |
32 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
42 ms |
404 KB |
Output is correct |
9 |
Correct |
48 ms |
352 KB |
Output is correct |
10 |
Correct |
36 ms |
420 KB |
Output is correct |
11 |
Correct |
60 ms |
404 KB |
Output is correct |
12 |
Correct |
32 ms |
332 KB |
Output is correct |
13 |
Correct |
212 ms |
476 KB |
Output is correct |
14 |
Correct |
197 ms |
548 KB |
Output is correct |
15 |
Correct |
113 ms |
504 KB |
Output is correct |
16 |
Correct |
183 ms |
604 KB |
Output is correct |
17 |
Correct |
154 ms |
452 KB |
Output is correct |
18 |
Correct |
120 ms |
596 KB |
Output is correct |
19 |
Correct |
221 ms |
484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
42 ms |
404 KB |
Output is correct |
9 |
Correct |
48 ms |
352 KB |
Output is correct |
10 |
Correct |
36 ms |
420 KB |
Output is correct |
11 |
Correct |
60 ms |
404 KB |
Output is correct |
12 |
Correct |
32 ms |
332 KB |
Output is correct |
13 |
Correct |
212 ms |
476 KB |
Output is correct |
14 |
Correct |
197 ms |
548 KB |
Output is correct |
15 |
Correct |
113 ms |
504 KB |
Output is correct |
16 |
Correct |
183 ms |
604 KB |
Output is correct |
17 |
Correct |
154 ms |
452 KB |
Output is correct |
18 |
Correct |
120 ms |
596 KB |
Output is correct |
19 |
Correct |
221 ms |
484 KB |
Output is correct |
20 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
21 |
Halted |
0 ms |
0 KB |
- |