TP-openmp/BE_OpenMP_2019/tree_branch/longest_branch_seq.c

38 lines
880 B
C
Raw Permalink Normal View History

2023-06-22 18:19:48 +00:00
#include "_aux.h"
void longest_branch_seq(node_t *root, unsigned int *longest_branch_weight, unsigned int *longest_branch_leaf){
*longest_branch_weight = 0;
*longest_branch_leaf = -1;
root->branch_weight = 0;
longest_branch_seq_rec(root, longest_branch_weight, longest_branch_leaf);
}
void longest_branch_seq_rec(node_t *root, unsigned int *longest_branch_weight, unsigned int *longest_branch_leaf){
int i;
process(root);
root->branch_weight += root->weight;
if(root->nc>0) {
for(i=0; i<root->nc; i++){
root->children[i].branch_weight = root->branch_weight;
longest_branch_seq_rec(root->children+i, longest_branch_weight, longest_branch_leaf);
}
} else {
if(root->branch_weight > *longest_branch_weight){
*longest_branch_weight = root->branch_weight;
*longest_branch_leaf = root->id;
}
}
}