#include <leetcode.h>
◆ countHighestScoreNodes()
int leetcode::count_nodes_with_the_highest_score::Solution::countHighestScoreNodes |
( |
vector< int > & |
parents | ) |
|
|
static |
在文件 leetcode.cpp 第 4153 行定义.
4155 auto nodes = vector<TreeNode *>(parents.size(),
nullptr);
4156 auto edges = vector(parents.size(), vector<int>());
4157 auto scores = vector<unsigned long long>(parents.size(), 0);
4158 for(
int i = 0; i < parents.size(); i++) {
4159 nodes[i] =
new TreeNode(i);
4160 if(parents[i] != -1) {
4161 edges[i].push_back(parents[i]);
4162 edges[parents[i]].push_back(i);
4165 TreeNode *
root =
nullptr;
4166 for(
int i = 0; i < parents.size(); i++) {
4167 if(parents[i] != -1) {
4168 nodes[parents[i]]->add_child(nodes[i]);
4174 unsigned long long max_score = 0;
4175 for(
int i = 0; i < parents.size(); i++) {
4176 unsigned long long score = 1;
4177 const auto *node = nodes[i];
4178 for(
const auto *child: node->get_children()) {
4179 score *= child->get_count();
4181 if(node->get_parent() !=
nullptr) {
4182 score *=
root->get_count() - node->get_count();
4184 max_score = max(max_score, score);
4187 return count(scores.begin(), scores.end(), max_score);
引用了 acwing::acwing836_408::root.
被这些函数引用 leetcode::count_nodes_with_the_highest_score::TEST().
该类的文档由以下文件生成: