# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
871018 |
2023-11-09T17:36:13 Z |
Ahmed57 |
Paths (RMI21_paths) |
C++17 |
|
2 ms |
600 KB |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,long long>> adj[101],tree[101];
long long ma = -1 , nod = 0;
void dfs(int i,int pr,long long co){
if(ma<co){
ma = co;
nod = i;
}
for(auto j:tree[i]){
if(j.first==pr)continue;
dfs(j.first,i,co+j.second);
}
}
long long all = 0;
bool clea(int i,int pr){
if(i==nod)return 1;
for(int j = 0;j<tree[i].size();j++){
if(tree[i][j].first==pr)continue;
all+=tree[i][j].second;
long long xd = tree[i][j].second;
tree[i][j].second = 0;
bool de = clea(tree[i][j].first,i);
if(de==0){
all-=xd;
tree[i][j].second = xd;
}else{
return 1;
}
}
return 0;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int n,k;
cin>>n>>k;
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 r = 1;r<=n;r++){
for(int i = 1;i<=n;i++){
tree[i].clear();
for(auto w:adj[i]){
tree[i].push_back(w);
}
}
int e = k;
all = 0;
while(e--){
ma = -1 , nod = 0;
dfs(r,0,0);
clea(r,0);
}
cout<<all<<endl;
}
}
Compilation message
Main.cpp: In function 'bool clea(int, int)':
Main.cpp:18:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int j = 0;j<tree[i].size();j++){
| ~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |