mirror of
https://github.com/xlucn/PAT.git
synced 2026-10-14 22:52:52 +08:00
55 lines
4.9 KiB
HTML
55 lines
4.9 KiB
HTML
Online Map
|
||
<div class="ques-view"><p>Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is the fastest. It is guaranteed that a path exists for any request.</p>
|
||
<h3 id="input-specification-">Input Specification:</h3>
|
||
<p>Each input file contains one test case. For each case, the first line gives two positive integers <span class="katex"><span class="katex-mathml"><math><mrow><mi>N</mi></mrow>N</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">N</span></span></span></span> (<span class="katex"><span class="katex-mathml"><math><mrow><mn>2</mn><mo>≤</mo><mi>N</mi><mo>≤</mo><mn>5</mn><mn>0</mn><mn>0</mn></mrow>2 \le N \le 500</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.8193em;vertical-align:-0.13597em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">2</span><span class="mrel">≤</span><span class="mord mathit" style="margin-right:0.10903em;">N</span><span class="mrel">≤</span><span class="mord mathrm">5</span><span class="mord mathrm">0</span><span class="mord mathrm">0</span></span></span></span>), and <span class="katex"><span class="katex-mathml"><math><mrow><mi>M</mi></mrow>M</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">M</span></span></span></span>, being the total number of streets intersections on a map, and the number of streets, respectively. Then <span class="katex"><span class="katex-mathml"><math><mrow><mi>M</mi></mrow>M</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">M</span></span></span></span> lines follow, each describes a street in the format:</p>
|
||
<pre><code>V1 V2 one-way length time
|
||
</code></pre><p>where <code>V1</code> and <code>V2</code> are the indices (from 0 to <span class="katex"><span class="katex-mathml"><math><mrow><mi>N</mi><mo>−</mo><mn>1</mn></mrow>N-1</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.76666em;vertical-align:-0.08333em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">N</span><span class="mbin">−</span><span class="mord mathrm">1</span></span></span></span>) of the two ends of the street; <code>one-way</code> is 1 if the street is one-way from <code>V1</code> to <code>V2</code>, or 0 if not; <code>length</code> is the length of the street; and <code>time</code> is the time taken to pass the street.</p>
|
||
<p>Finally a pair of source and destination is given.</p>
|
||
<h3 id="output-specification-">Output Specification:</h3>
|
||
<p>For each case, first print the shortest path from the source to the destination with distance <code>D</code> in the format:</p>
|
||
<pre><code>Distance = D: source -> v1 -> ... -> destination
|
||
</code></pre><p>Then in the next line print the fastest path with total time <code>T</code>:</p>
|
||
<pre><code>Time = T: source -> w1 -> ... -> destination
|
||
</code></pre><p>In case the shortest path is not unique, output the fastest one among the shortest paths, which is guaranteed to be unique. In case the fastest path is not unique, output the one that passes through the fewest intersections, which is guaranteed to be unique.</p>
|
||
<p>In case the shortest and the fastest paths are identical, print them in one line in the format:</p>
|
||
<pre><code>Distance = D; Time = T: source -> u1 -> ... -> destination
|
||
</code></pre><h3 id="sample-input-1-">Sample Input 1:</h3>
|
||
<pre><code class="lang-in">10 15
|
||
0 1 0 1 1
|
||
8 0 0 1 1
|
||
4 8 1 1 1
|
||
3 4 0 3 2
|
||
3 9 1 4 1
|
||
0 6 0 1 1
|
||
7 5 1 2 1
|
||
8 5 1 2 1
|
||
2 3 0 2 2
|
||
2 1 1 1 1
|
||
1 3 0 3 1
|
||
1 4 0 1 1
|
||
9 7 1 3 1
|
||
5 1 0 5 2
|
||
6 5 1 1 2
|
||
3 5
|
||
</code></pre>
|
||
<h3 id="sample-output-1-">Sample Output 1:</h3>
|
||
<pre><code class="lang-out">Distance = 6: 3 -> 4 -> 8 -> 5
|
||
Time = 3: 3 -> 1 -> 5
|
||
</code></pre>
|
||
<h3 id="sample-input-2-">Sample Input 2:</h3>
|
||
<pre><code class="lang-in">7 9
|
||
0 4 1 1 1
|
||
1 6 1 1 3
|
||
2 6 1 1 1
|
||
2 5 1 2 2
|
||
3 0 0 1 1
|
||
3 1 1 1 3
|
||
3 2 1 1 2
|
||
4 5 0 2 2
|
||
6 5 1 1 2
|
||
3 5
|
||
</code></pre>
|
||
<h3 id="sample-output-2-">Sample Output 2:</h3>
|
||
<pre><code class="lang-out">Distance = 3; Time = 4: 3 -> 2 -> 5
|
||
</code></pre>
|
||
</div> |