1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 19:18:14 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/网络延迟时间 [network-delay-time].html

45 lines
1.7 KiB
HTML
Raw Normal View History

2022-03-27 20:46:41 +08:00
<p><code>n</code> 个网络节点,标记为&nbsp;<code>1</code>&nbsp;<code>n</code></p>
<p>给你一个列表&nbsp;<code>times</code>,表示信号经过 <strong>有向</strong> 边的传递时间。&nbsp;<code>times[i] = (u<sub>i</sub>, v<sub>i</sub>, w<sub>i</sub>)</code>,其中&nbsp;<code>u<sub>i</sub></code>&nbsp;是源节点,<code>v<sub>i</sub></code>&nbsp;是目标节点, <code>w<sub>i</sub></code>&nbsp;是一个信号从源节点传递到目标节点的时间。</p>
<p>现在,从某个节点&nbsp;<code>K</code>&nbsp;发出一个信号。需要多久才能使所有节点都收到信号?如果不能使所有节点收到信号,返回&nbsp;<code>-1</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/05/23/931_example_1.png" style="height: 220px; width: 200px;" /></p>
<pre>
<strong>输入:</strong>times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2
<strong>输出:</strong>2
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>times = [[1,2,1]], n = 2, k = 1
<strong>输出:</strong>1
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>times = [[1,2,1]], n = 2, k = 2
<strong>输出:</strong>-1
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= k &lt;= n &lt;= 100</code></li>
<li><code>1 &lt;= times.length &lt;= 6000</code></li>
<li><code>times[i].length == 3</code></li>
<li><code>1 &lt;= u<sub>i</sub>, v<sub>i</sub> &lt;= n</code></li>
<li><code>u<sub>i</sub> != v<sub>i</sub></code></li>
<li><code>0 &lt;= w<sub>i</sub> &lt;= 100</code></li>
<li>所有 <code>(u<sub>i</sub>, v<sub>i</sub>)</code> 对都 <strong>互不相同</strong>(即,不含重复边)</li>
</ul>