#include <leetcode.h>
◆ networkBecomesIdle()
int leetcode::the_time_when_the_network_becomes_idle::Solution::networkBecomesIdle |
( |
vector< vector< int > > & |
edges, |
|
|
vector< int > & |
patience |
|
) |
| |
|
static |
在文件 leetcode.cpp 第 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]);
4858 for(
auto edge: edges) {
4859 um[edge[0]]->linked.insert(edge[1]);
4860 um[edge[1]]->linked.insert(edge[0]);
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();
4868 if(nodes.contains(num)) {
4870 Node *node = um[num];
4872 for(
auto next: node->linked) {
4873 if(nodes.contains(next)) {
4874 pq.push(make_pair(next, len + 1));
4880 for(
auto [num, node]: um) {
4882 int resent_num = node->time * 2 / node->patience;
4883 if(node->time * 2 % node->patience == 0) {
4886 ans = max(ans, resent_num * node->patience + 2 * node->time + 1);
引用了 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().
该类的文档由以下文件生成: