Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 34519a5

Browse files
Create README - LeetHub
1 parent acfd103 commit 34519a5

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<h2><a href="https://leetcode.com/problems/second-minimum-time-to-reach-destination/"><div id="big-omega-company-tags"><div id="big-omega-topbar"><div class="companyTagsContainer" style="overflow-x: scroll; flex-wrap: nowrap;"><div class="companyTagsContainer--tag">No companies found for this problem</div></div><div class="companyTagsContainer--chevron"><div><svg version="1.1" id="icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 32 32" fill="#4087F1" xml:space="preserve" style="width: 20px;"><polygon points="16,22 6,12 7.4,10.6 16,19.2 24.6,10.6 26,12 "></polygon><rect id="_x3C_Transparent_Rectangle_x3E_" class="st0" fill="none" width="32" height="32"></rect></svg></div></div></div></div>2045. Second Minimum Time to Reach Destination</a></h2><h3>Hard</h3><hr><div><p>A city is represented as a <strong>bi-directional connected</strong> graph with <code>n</code> vertices where each vertex is labeled from <code>1</code> to <code>n</code> (<strong>inclusive</strong>). The edges in the graph are represented as a 2D integer array <code>edges</code>, where each <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> denotes a bi-directional edge between vertex <code>u<sub>i</sub></code> and vertex <code>v<sub>i</sub></code>. Every vertex pair is connected by <strong>at most one</strong> edge, and no vertex has an edge to itself. The time taken to traverse any edge is <code>time</code> minutes.</p>
2+
3+
<p>Each vertex has a traffic signal which changes its color from <strong>green</strong> to <strong>red</strong> and vice versa every&nbsp;<code>change</code> minutes. All signals change <strong>at the same time</strong>. You can enter a vertex at <strong>any time</strong>, but can leave a vertex <strong>only when the signal is green</strong>. You <strong>cannot wait </strong>at a vertex if the signal is <strong>green</strong>.</p>
4+
5+
<p>The <strong>second minimum value</strong> is defined as the smallest value<strong> strictly larger </strong>than the minimum value.</p>
6+
7+
<ul>
8+
<li>For example the second minimum value of <code>[2, 3, 4]</code> is <code>3</code>, and the second minimum value of <code>[2, 2, 4]</code> is <code>4</code>.</li>
9+
</ul>
10+
11+
<p>Given <code>n</code>, <code>edges</code>, <code>time</code>, and <code>change</code>, return <em>the <strong>second minimum time</strong> it will take to go from vertex </em><code>1</code><em> to vertex </em><code>n</code>.</p>
12+
13+
<p><strong>Notes:</strong></p>
14+
15+
<ul>
16+
<li>You can go through any vertex <strong>any</strong> number of times, <strong>including</strong> <code>1</code> and <code>n</code>.</li>
17+
<li>You can assume that when the journey <strong>starts</strong>, all signals have just turned <strong>green</strong>.</li>
18+
</ul>
19+
20+
<p>&nbsp;</p>
21+
<p><strong class="example">Example 1:</strong></p>
22+
<img alt="" src="https://assets.leetcode.com/uploads/2021/09/29/e1.png" style="width: 200px; height: 250px;"> <img alt="" src="https://assets.leetcode.com/uploads/2021/09/29/e2.png" style="width: 200px; height: 250px;">
23+
<pre><strong>Input:</strong> n = 5, edges = [[1,2],[1,3],[1,4],[3,4],[4,5]], time = 3, change = 5
24+
<strong>Output:</strong> 13
25+
<strong>Explanation:</strong>
26+
The figure on the left shows the given graph.
27+
The blue path in the figure on the right is the minimum time path.
28+
The time taken is:
29+
- Start at 1, time elapsed=0
30+
- 1 -&gt; 4: 3 minutes, time elapsed=3
31+
- 4 -&gt; 5: 3 minutes, time elapsed=6
32+
Hence the minimum time needed is 6 minutes.
33+
34+
The red path shows the path to get the second minimum time.
35+
- Start at 1, time elapsed=0
36+
- 1 -&gt; 3: 3 minutes, time elapsed=3
37+
- 3 -&gt; 4: 3 minutes, time elapsed=6
38+
- Wait at 4 for 4 minutes, time elapsed=10
39+
- 4 -&gt; 5: 3 minutes, time elapsed=13
40+
Hence the second minimum time is 13 minutes.
41+
</pre>
42+
43+
<p><strong class="example">Example 2:</strong></p>
44+
<img alt="" src="https://assets.leetcode.com/uploads/2021/09/29/eg2.png" style="width: 225px; height: 50px;">
45+
<pre><strong>Input:</strong> n = 2, edges = [[1,2]], time = 3, change = 2
46+
<strong>Output:</strong> 11
47+
<strong>Explanation:</strong>
48+
The minimum time path is 1 -&gt; 2 with time = 3 minutes.
49+
The second minimum time path is 1 -&gt; 2 -&gt; 1 -&gt; 2 with time = 11 minutes.</pre>
50+
51+
<p>&nbsp;</p>
52+
<p><strong>Constraints:</strong></p>
53+
54+
<ul>
55+
<li><code>2 &lt;= n &lt;= 10<sup>4</sup></code></li>
56+
<li><code>n - 1 &lt;= edges.length &lt;= min(2 * 10<sup>4</sup>, n * (n - 1) / 2)</code></li>
57+
<li><code>edges[i].length == 2</code></li>
58+
<li><code>1 &lt;= u<sub>i</sub>, v<sub>i</sub> &lt;= n</code></li>
59+
<li><code>u<sub>i</sub> != v<sub>i</sub></code></li>
60+
<li>There are no duplicate edges.</li>
61+
<li>Each vertex can be reached directly or indirectly from every other vertex.</li>
62+
<li><code>1 &lt;= time, change &lt;= 10<sup>3</sup></code></li>
63+
</ul>
64+
</div>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /