mirror of
https://github.com/xlucn/PAT.git
synced 2026-11-05 06:37:35 +08:00
47 lines
3.3 KiB
HTML
47 lines
3.3 KiB
HTML
Uniqueness of MST
|
||
<div class="ques-view"><p>Given any weighted undirected graph, there exists at least one minimum spanning tree (MST) if the graph is connected. Sometimes the MST may not be unique though. Here you are supposed to calculate the minimum total weight of the MST, and also tell if it is unique or not.</p>
|
||
<h3 id="input-specification-">Input Specification:</h3>
|
||
<p>Each input file contains one test case. Each case starts with a line containing 2 numbers N (<span class="katex"><span class="katex-mathml"><math><mrow><mo>≤</mo></mrow>\le</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.63597em;"></span><span class="strut bottom" style="height:0.7719400000000001em;vertical-align:-0.13597em;"></span><span class="base textstyle uncramped"><span class="mrel">≤</span></span></span></span> 500), and M, which are the total number of vertices, and the number of edges, respectively. Then M lines follow, each describes an edge by 3 integers:</p>
|
||
<pre><code>V1 V2 Weight
|
||
</code></pre><p>where <code>V1</code> and <code>V2</code> are the two ends of the edge (the vertices are numbered from 1 to N), and <code>Weight</code> is the positive weight on that edge. It is guaranteed that the total weight of the graph will not exceed <span class="katex"><span class="katex-mathml"><math><mrow><msup><mn>2</mn><mrow><mn>3</mn><mn>0</mn></mrow></msup></mrow>2^{30}</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"><span class="mord mathrm">2</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 scriptstyle uncramped mtight"><span class="mord mathrm mtight">3</span><span class="mord mathrm mtight">0</span></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>.</p>
|
||
<h3 id="output-specification-">Output Specification:</h3>
|
||
<p>For each test case, first print in a line the total weight of the minimum spanning tree if there exists one, or else print <code>No MST</code> instead. Then if the MST exists, print in the next line <code>Yes</code> if the tree is unique, or <code>No</code> otherwise. There there is no MST, print the number of connected components instead.</p>
|
||
<h3 id="sample-input-1-">Sample Input 1:</h3>
|
||
<pre><code class="lang-in">5 7
|
||
1 2 6
|
||
5 1 1
|
||
2 3 4
|
||
3 4 3
|
||
4 1 7
|
||
2 4 2
|
||
4 5 5
|
||
</code></pre>
|
||
<h3 id="sample-output-1-">Sample Output 1:</h3>
|
||
<pre><code class="lang-out">11
|
||
Yes
|
||
</code></pre>
|
||
<h3 id="sample-input-2-">Sample Input 2:</h3>
|
||
<pre><code class="lang-in">4 5
|
||
1 2 1
|
||
2 3 1
|
||
3 4 2
|
||
4 1 2
|
||
3 1 3
|
||
</code></pre>
|
||
<h3 id="sample-output-2-">Sample Output 2:</h3>
|
||
<pre><code class="lang-out">4
|
||
No
|
||
</code></pre>
|
||
<h3 id="sample-input-3-">Sample Input 3:</h3>
|
||
<pre><code class="lang-in">5 5
|
||
1 2 1
|
||
2 3 1
|
||
3 4 2
|
||
4 1 2
|
||
3 1 3
|
||
</code></pre>
|
||
<h3 id="sample-output-3-">Sample Output 3:</h3>
|
||
<pre><code class="lang-out">No MST
|
||
2
|
||
</code></pre>
|
||
</div> |