# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
646938 |
2022-10-01T07:57:25 Z |
ksu2009en |
Paths (RMI21_paths) |
C++17 |
|
600 ms |
16884 KB |
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <cstring>
#include <unordered_map>
using namespace std;
typedef long long ll;
vector<vector<pair<ll, ll>>>d, d2;
ll mx = -1, pos = 0;
void dfs(ll v, ll par, ll cost){
if(cost > mx){
mx = cost;
pos = v;
}
for(auto i: d2[v]){
if(i.first != par){
dfs(i.first, v, cost + i.second);
}
}
}
bool dfs_2(ll v, ll par){
if(v == pos)
return true;
for(auto &i: d2[v]){
if(i.first == par)
continue;
if(dfs_2(i.first, v)){
i.second = 0;
return true;
}
}
return false;
}
int main(){
ll n, k;
cin >> n >> k;
d.resize(n + 1);
for(int i = 0; i < n - 1; i++){
ll x, y, c;
cin >> x >> y >> c;
d[x].push_back({y, c});
d[y].push_back({x, c});
}
for(int root = 1; root <= n; root++){
d2 = d;
ll ans = 0;
for(int step = 1; step <= k; step++){
mx = -1, pos = 0;
dfs(root, -1, 0);
bool no_need = dfs_2(root, -1);
ans += mx;
}
cout << ans << endl;
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:77:18: warning: unused variable 'no_need' [-Wunused-variable]
77 | bool no_need = dfs_2(root, -1);
| ^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
8 ms |
212 KB |
Output is correct |
4 |
Correct |
8 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
212 KB |
Output is correct |
7 |
Correct |
15 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
8 ms |
212 KB |
Output is correct |
4 |
Correct |
8 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
212 KB |
Output is correct |
7 |
Correct |
15 ms |
212 KB |
Output is correct |
8 |
Execution timed out |
1087 ms |
576 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
8 ms |
212 KB |
Output is correct |
4 |
Correct |
8 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
212 KB |
Output is correct |
7 |
Correct |
15 ms |
212 KB |
Output is correct |
8 |
Execution timed out |
1087 ms |
576 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1081 ms |
16884 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
8 ms |
212 KB |
Output is correct |
4 |
Correct |
8 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
212 KB |
Output is correct |
7 |
Correct |
15 ms |
212 KB |
Output is correct |
8 |
Execution timed out |
1087 ms |
576 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |