<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=2888_-_Spanning_Tree</id>
	<title>2888 - Spanning Tree - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=2888_-_Spanning_Tree"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=2888_-_Spanning_Tree&amp;action=history"/>
	<updated>2026-05-01T12:34:52Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://wiki.universitas.ro/index.php?title=2888_-_Spanning_Tree&amp;diff=9137&amp;oldid=prev</id>
		<title>Rus Marius: /* Date de ieșire */</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=2888_-_Spanning_Tree&amp;diff=9137&amp;oldid=prev"/>
		<updated>2024-01-06T19:55:04Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Date de ieșire&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:55, 6 January 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l9&quot;&gt;Line 9:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 9:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Date de ieșire =&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Date de ieșire =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Programul va afișa pe ecran numărul arborilor parțiali ai grafului.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Programul va afișa pe ecran numărul arborilor parțiali ai grafului&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.În cazul în care restricțiile nu sunt îndeplinite, se va afișa mesajul &quot;Datele nu corespund restrictiilor impuse&quot;&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Restricții și precizări =&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Restricții și precizări =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Rus Marius</name></author>
	</entry>
	<entry>
		<id>https://wiki.universitas.ro/index.php?title=2888_-_Spanning_Tree&amp;diff=9136&amp;oldid=prev</id>
		<title>Rus Marius: Pagină nouă: == Enunț == Se consideră un graf neorientat conex cu &lt;code&gt;n&lt;/code&gt; noduri și &lt;code&gt;n&lt;/code&gt; muchii.  = Cerința = Să se determine numărul arborilor parțiali ai grafului.  = Date de intrare = Programul citește de la tastatură numărul &lt;code&gt;n&lt;/code&gt;, iar apoi &lt;code&gt;n&lt;/code&gt; perechi de numere naturale &lt;code&gt;x y&lt;/code&gt; reprezentând cele &lt;code&gt;n&lt;/code&gt; muchii.  = Date de ieșire = Programul va afișa pe ecran numărul arborilor parțiali ai grafului.  = Restricții și...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=2888_-_Spanning_Tree&amp;diff=9136&amp;oldid=prev"/>
		<updated>2024-01-06T19:54:54Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: == Enunț == Se consideră un graf neorientat conex cu &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; noduri și &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; muchii.  = Cerința = Să se determine numărul arborilor parțiali ai grafului.  = Date de intrare = Programul citește de la tastatură numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, iar apoi &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; perechi de numere naturale &amp;lt;code&amp;gt;x y&amp;lt;/code&amp;gt; reprezentând cele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; muchii.  = Date de ieșire = Programul va afișa pe ecran numărul arborilor parțiali ai grafului.  = Restricții și...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Enunț ==&lt;br /&gt;
Se consideră un graf neorientat conex cu &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; noduri și &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; muchii.&lt;br /&gt;
&lt;br /&gt;
= Cerința =&lt;br /&gt;
Să se determine numărul arborilor parțiali ai grafului.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Programul citește de la tastatură numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, iar apoi &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; perechi de numere naturale &amp;lt;code&amp;gt;x y&amp;lt;/code&amp;gt; reprezentând cele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; muchii.&lt;br /&gt;
&lt;br /&gt;
= Date de ieșire =&lt;br /&gt;
Programul va afișa pe ecran numărul arborilor parțiali ai grafului.&lt;br /&gt;
&lt;br /&gt;
= Restricții și precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ n ≤ 30.000&amp;lt;/code&amp;gt;&lt;br /&gt;
* cele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; muchii sunt distincte două câte două&lt;br /&gt;
&lt;br /&gt;
= Exemplul 1: =&lt;br /&gt;
Intrare&lt;br /&gt;
 7&lt;br /&gt;
 1 4&lt;br /&gt;
 1 5&lt;br /&gt;
 2 3&lt;br /&gt;
 2 4&lt;br /&gt;
 4 5&lt;br /&gt;
 4 6&lt;br /&gt;
 4 7&lt;br /&gt;
Ieșire&lt;br /&gt;
 3&lt;br /&gt;
&lt;br /&gt;
= Exemplul 2: =&lt;br /&gt;
Intrare&lt;br /&gt;
 30001&lt;br /&gt;
Ieșire&lt;br /&gt;
 Datele nu corespund restrictiilor impuse&lt;br /&gt;
&lt;br /&gt;
== Rezolvare ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
from collections import deque&lt;br /&gt;
&lt;br /&gt;
def check_restriction_n(value):&lt;br /&gt;
    if not (1 &amp;lt;= value &amp;lt;= 30000):&lt;br /&gt;
        print(&amp;quot;Datele nu corespund restrictiilor impuse&amp;quot;)&lt;br /&gt;
        exit()&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    n = int(input())&lt;br /&gt;
    check_restriction_n(n)&lt;br /&gt;
&lt;br /&gt;
    v = [[] for _ in range(30001)]&lt;br /&gt;
    t = [0] * 30001&lt;br /&gt;
    cnt = 0&lt;br /&gt;
    q = deque()&lt;br /&gt;
&lt;br /&gt;
    for _ in range(n):&lt;br /&gt;
        x, y = map(int, input().split())&lt;br /&gt;
        v[x].append(y)&lt;br /&gt;
        v[y].append(x)&lt;br /&gt;
        t[x] += 1&lt;br /&gt;
        t[y] += 1&lt;br /&gt;
&lt;br /&gt;
    for i in range(1, n + 1):&lt;br /&gt;
        if t[i] == 1:&lt;br /&gt;
            q.append(i)&lt;br /&gt;
&lt;br /&gt;
    while q:&lt;br /&gt;
        x = q.popleft()&lt;br /&gt;
        for y in v[x]:&lt;br /&gt;
            if t[y]:&lt;br /&gt;
                t[y] -= 1&lt;br /&gt;
                if t[y] == 1:&lt;br /&gt;
                    q.append(y)&lt;br /&gt;
        t[x] = 0&lt;br /&gt;
&lt;br /&gt;
    for i in range(1, n + 1):&lt;br /&gt;
        if t[i] == 2:&lt;br /&gt;
            cnt += 1&lt;br /&gt;
&lt;br /&gt;
    print(cnt)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    main()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rus Marius</name></author>
	</entry>
</feed>