mirror of
https://github.com/xlucn/PAT.git
synced 2026-11-04 00:38:13 +08:00
29 lines
5.8 KiB
HTML
29 lines
5.8 KiB
HTML
Currency Exchange Centers
|
||
<div class="ques-view"><p>There are currently 168 internationally recognized unique national currencies in this world. But let us assume that we have business with other species in the entire universe... To change one currency to another, we need currency exchange centers, and they charge fees for it. Now given a list of informations of these centers, you are supposed to find a collection of the centers so that we can make change between any two currencies (directly or indirectly) through them. Since such a kind of collection may not be unique, you must find the one with the minimum total fees; and if there are still more than one solution, find the one with the minimum number of centers -- it is guaranteed that such a solution is unique.</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> 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> (both no more than <span class="katex"><span class="katex-mathml"><math><mrow><mn>1</mn><msup><mn>0</mn><mn>4</mn></msup></mrow>10^4</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.8141079999999999em;"></span><span class="strut bottom" style="height:0.8141079999999999em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">1</span><span class="mord"><span class="mord mathrm">0</span><span class="msupsub"><span class="vlist"><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;"></span></span><span class="reset-textstyle scriptstyle uncramped mtight"><span class="mord mathrm mtight">4</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;"></span></span></span></span></span></span></span></span></span>), being the total numbers of currencies and the size of the list of currency exchange center informations, 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 piece of information in the following format:</p>
|
||
<pre><code>C1 C2 Center Fee
|
||
</code></pre><p>where <code>C1</code> and <code>C2</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 currencies; <code>Center</code> is a string of 3 capital English letters representing the name of a center; and <code>Fee</code> is a positive integer no more than <span class="katex"><span class="katex-mathml"><math><mrow><mn>1</mn><msup><mn>0</mn><mn>4</mn></msup></mrow>10^4</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.8141079999999999em;"></span><span class="strut bottom" style="height:0.8141079999999999em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">1</span><span class="mord"><span class="mord mathrm">0</span><span class="msupsub"><span class="vlist"><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;"></span></span><span class="reset-textstyle scriptstyle uncramped mtight"><span class="mord mathrm mtight">4</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;"></span></span></span></span></span></span></span></span></span>. It is guaranteed that at most one exchange center is given for each pair of different currencies.</p>
|
||
<h3 id="output-specification-">Output Specification:</h3>
|
||
<p>Print in the first line the total number of currency exchange centered being collected, and the total amount of fees they charge, separated by a space. Then in the following lines, print the centers which must be collected in the same format as the input. The centers must be output in alphabetical order of their names, and if there is a tie, in ascending order of their fees. It is guaranteed that such a solution exists and is unique.</p>
|
||
<h3 id="sample-input-">Sample Input:</h3>
|
||
<pre><code class="lang-in">6 9
|
||
4 3 CBC 32
|
||
1 5 HSB 43
|
||
1 0 HSB 32
|
||
0 2 CTB 28
|
||
4 2 CBC 19
|
||
2 3 CBC 28
|
||
0 4 ABC 28
|
||
1 2 ABC 32
|
||
3 1 CTB 19
|
||
</code></pre>
|
||
<h3 id="sample-output-">Sample Output:</h3>
|
||
<pre><code class="lang-out">3 137
|
||
4 2 CBC 19
|
||
2 3 CBC 28
|
||
3 1 CTB 19
|
||
0 2 CTB 28
|
||
1 5 HSB 43
|
||
</code></pre>
|
||
</div> |