<?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=0537_-_Componente_Conexe_2</id>
	<title>0537 - Componente Conexe 2 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=0537_-_Componente_Conexe_2"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0537_-_Componente_Conexe_2&amp;action=history"/>
	<updated>2026-05-01T04:00:49Z</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=0537_-_Componente_Conexe_2&amp;diff=7973&amp;oldid=prev</id>
		<title>Simina: Pagină nouă: = Cerinţa = Se dă lista muchiilor unui graf neorientat. Să se determine numărul de muchii care pot fi eliminate din graf astfel încât numărul de componente conexe ale grafului să nu se modifice.  = Date de intrare = Fişierul de intrare &lt;code&gt;componenteconexe2IN.txt&lt;/code&gt; conţine pe prima linie numărul &lt;code&gt;n&lt;/code&gt;, reprezentând numărul de vârfuri ale grafului. Fiecare dintre următoarele linii conține câte o pereche de numere &lt;code&gt;i j&lt;/code&gt;, cu semnifica...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0537_-_Componente_Conexe_2&amp;diff=7973&amp;oldid=prev"/>
		<updated>2023-12-13T10:56:35Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: = Cerinţa = Se dă lista muchiilor unui graf neorientat. Să se determine numărul de muchii care pot fi eliminate din graf astfel încât numărul de componente conexe ale grafului să nu se modifice.  = Date de intrare = Fişierul de intrare &amp;lt;code&amp;gt;componenteconexe2IN.txt&amp;lt;/code&amp;gt; conţine pe prima linie numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, reprezentând numărul de vârfuri ale grafului. Fiecare dintre următoarele linii conține câte o pereche de numere &amp;lt;code&amp;gt;i j&amp;lt;/code&amp;gt;, cu semnifica...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Cerinţa =&lt;br /&gt;
Se dă lista muchiilor unui graf neorientat. Să se determine numărul de muchii care pot fi eliminate din graf astfel încât numărul de componente conexe ale grafului să nu se modifice.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fişierul de intrare &amp;lt;code&amp;gt;componenteconexe2IN.txt&amp;lt;/code&amp;gt; conţine pe prima linie numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, reprezentând numărul de vârfuri ale grafului. Fiecare dintre următoarele linii conține câte o pereche de numere &amp;lt;code&amp;gt;i j&amp;lt;/code&amp;gt;, cu semnificația că există muchie între &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;j&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Date de ieşire =&lt;br /&gt;
Fişierul de ieşire &amp;lt;code&amp;gt;componenteconexe2OUT.txt&amp;lt;/code&amp;gt; va conţine pe prima linie numărul &amp;lt;code&amp;gt;NR&amp;lt;/code&amp;gt; de muchii care pot fi eliminate.&lt;br /&gt;
&lt;br /&gt;
= Restricţii şi precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ n ≤ 100&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ i , j ≤ n&amp;lt;/code&amp;gt;&lt;br /&gt;
* în fișierul de intrare muchiile se pot repeta&lt;br /&gt;
&lt;br /&gt;
= Exemplul 1 =&lt;br /&gt;
&amp;lt;code&amp;gt;componenteconexe2IN.txt&amp;lt;/code&amp;gt; &lt;br /&gt;
 7&lt;br /&gt;
 1 4&lt;br /&gt;
 1 6&lt;br /&gt;
 2 3&lt;br /&gt;
 2 7&lt;br /&gt;
 3 7&lt;br /&gt;
 4 5&lt;br /&gt;
 4 6&lt;br /&gt;
 6 5&lt;br /&gt;
&amp;lt;code&amp;gt;componenteconexe2OUT.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 3&lt;br /&gt;
&lt;br /&gt;
= Exemplul 2 =&lt;br /&gt;
&amp;lt;code&amp;gt;componenteconexe2IN.txt&amp;lt;/code&amp;gt; &lt;br /&gt;
 101&lt;br /&gt;
&amp;lt;code&amp;gt;componenteconexe2OUT.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 Datele nu corespund restrictiilor impuse&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
def verifica_restrictii(n, muchii):&lt;br /&gt;
    if not (1 &amp;lt;= n &amp;lt;= 100):&lt;br /&gt;
        return False&lt;br /&gt;
    for muchie in muchii:&lt;br /&gt;
        if not (1 &amp;lt;= muchie[0] &amp;lt;= n) or not (1 &amp;lt;= muchie[1] &amp;lt;= n):&lt;br /&gt;
            return False&lt;br /&gt;
    return True&lt;br /&gt;
&lt;br /&gt;
def dfs(graful, vizitate, nod):&lt;br /&gt;
    vizitate[nod] = True&lt;br /&gt;
    for vecin in graful[nod]:&lt;br /&gt;
        if not vizitate[vecin]:&lt;br /&gt;
            dfs(graful, vizitate, vecin)&lt;br /&gt;
&lt;br /&gt;
def numar_componente_conexe(graful, n):&lt;br /&gt;
    vizitate = [False] * (n + 1)&lt;br /&gt;
    numar = 0&lt;br /&gt;
    for nod in range(1, n + 1):&lt;br /&gt;
        if not vizitate[nod]:&lt;br /&gt;
            numar += 1&lt;br /&gt;
            dfs(graful, vizitate, nod)&lt;br /&gt;
    return numar&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    with open(&amp;quot;componenteconexe2IN.txt&amp;quot;, &amp;quot;r&amp;quot;) as f:&lt;br /&gt;
        n = int(f.readline())&lt;br /&gt;
        muchii = [tuple(map(int, linie.split())) for linie in f]&lt;br /&gt;
&lt;br /&gt;
    if not verifica_restrictii(n, muchii):&lt;br /&gt;
        with open(&amp;quot;componenteconexe2OUT.txt&amp;quot;, &amp;quot;w&amp;quot;) as f_out:&lt;br /&gt;
            f_out.write(&amp;quot;Datele nu corespund restrictiilor impuse&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
&lt;br /&gt;
    graful = {i: [] for i in range(1, n + 1)}&lt;br /&gt;
&lt;br /&gt;
    for muchie in muchii:&lt;br /&gt;
        graful[muchie[0]].append(muchie[1])&lt;br /&gt;
        graful[muchie[1]].append(muchie[0])&lt;br /&gt;
&lt;br /&gt;
    numar_initial = numar_componente_conexe(graful, n)&lt;br /&gt;
&lt;br /&gt;
    numar_muchii_eliminate = 0&lt;br /&gt;
&lt;br /&gt;
    for muchie in muchii:&lt;br /&gt;
        graful[muchie[0]].remove(muchie[1])&lt;br /&gt;
        graful[muchie[1]].remove(muchie[0])&lt;br /&gt;
&lt;br /&gt;
        numar_final = numar_componente_conexe(graful, n)&lt;br /&gt;
&lt;br /&gt;
        if numar_final == numar_initial:&lt;br /&gt;
            numar_muchii_eliminate += 1&lt;br /&gt;
        else:&lt;br /&gt;
            graful[muchie[0]].append(muchie[1])&lt;br /&gt;
            graful[muchie[1]].append(muchie[0])&lt;br /&gt;
&lt;br /&gt;
    with open(&amp;quot;componenteconexe2OUT.txt&amp;quot;, &amp;quot;w&amp;quot;) as f_out:&lt;br /&gt;
        if numar_muchii_eliminate &amp;gt; 0:&lt;br /&gt;
            f_out.write(str(numar_muchii_eliminate))&lt;br /&gt;
        else:&lt;br /&gt;
            f_out.write(&amp;quot;Datele nu corespund restrictiilor impuse&amp;quot;)&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>Simina</name></author>
	</entry>
</feed>