problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::the_time_when_the_network_becomes_idle::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static int networkBecomesIdle (vector< vector< int > > &edges, vector< int > &patience)
 

详细描述

在文件 leetcode.h1867 行定义.

成员函数说明

◆ networkBecomesIdle()

int leetcode::the_time_when_the_network_becomes_idle::Solution::networkBecomesIdle ( vector< vector< int > > &  edges,
vector< int > &  patience 
)
static

在文件 leetcode.cpp4851 行定义.

4851 {
4852 unordered_map<int, Node *> um;
4853 unordered_set<int> nodes;
4854 for(int i = 0; i < patience.size(); i++) {
4855 um[i] = new Node(i, patience[i]);
4856 nodes.insert(i);
4857 }
4858 for(auto edge: edges) {
4859 um[edge[0]]->linked.insert(edge[1]);
4860 um[edge[1]]->linked.insert(edge[0]);
4861 }
4862 auto comp = [](const pair<int, int> &s1, const pair<int, int> &s2) -> bool { return s1.second > s2.second; };
4863 priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(comp)> pq;
4864 pq.push(make_pair(0, 0));
4865 while(!nodes.empty()) {
4866 auto [num, len] = pq.top();
4867 pq.pop();
4868 if(nodes.contains(num)) {
4869 nodes.erase(num);
4870 Node *node = um[num];
4871 node->time = len;
4872 for(auto next: node->linked) {
4873 if(nodes.contains(next)) {
4874 pq.push(make_pair(next, len + 1));
4875 }
4876 }
4877 }
4878 }
4879 int ans = 0;
4880 for(auto [num, node]: um) {
4881 if(num != 0) {
4882 int resent_num = node->time * 2 / node->patience;
4883 if(node->time * 2 % node->patience == 0) {
4884 resent_num--;
4885 }
4886 ans = max(ans, resent_num * node->patience + 2 * node->time + 1);
4887 }
4888 }
4889 return ans;
4890 }

引用了 leetcode::the_time_when_the_network_becomes_idle::Node::linked , 以及 leetcode::the_time_when_the_network_becomes_idle::Node::time.

被这些函数引用 leetcode::the_time_when_the_network_becomes_idle::TEST().


该类的文档由以下文件生成: