<?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=0421_-_Graf_Partial_1</id>
	<title>0421 - Graf Partial 1 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=0421_-_Graf_Partial_1"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0421_-_Graf_Partial_1&amp;action=history"/>
	<updated>2026-05-02T22:03:47Z</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=0421_-_Graf_Partial_1&amp;diff=8186&amp;oldid=prev</id>
		<title>Corjuc Eunice at 15:00, 16 December 2023</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0421_-_Graf_Partial_1&amp;diff=8186&amp;oldid=prev"/>
		<updated>2023-12-16T15:00:15Z</updated>

		<summary type="html">&lt;p&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 15:00, 16 December 2023&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-l3&quot;&gt;Line 3:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 3:&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 intrare =&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 intrare =&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;Fişierul de intrare &amp;lt;code&amp;gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;graf_partial_1&lt;/del&gt;.&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;in&lt;/del&gt;&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;/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;Fişierul de intrare &amp;lt;code&amp;gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;graf_partial_1IN&lt;/ins&gt;.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;txt&lt;/ins&gt;&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;/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;= 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;Fişierul de ieşire &amp;lt;code&amp;gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;graf_partial_1&lt;/del&gt;.&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;out&lt;/del&gt;&amp;lt;/code&amp;gt; va conţine pe prime linie numărul de muchii eliminate, iar pe următoarele linii matricea de adiacență a grafului parțial obținut, câte o linie a matricei pe o linie a fișierului, elementele de pe fiecare linie fiind separate prin exact un spațiu.&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;Fişierul de ieşire &amp;lt;code&amp;gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;graf_partial_1OUT&lt;/ins&gt;.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;txt&lt;/ins&gt;&amp;lt;/code&amp;gt; va conţine pe prime linie numărul de muchii eliminate, iar pe următoarele linii matricea de adiacență a grafului parțial obținut, câte o linie a matricei pe o linie a fișierului, elementele de pe fiecare linie fiind separate prin exact un spațiu.&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>Corjuc Eunice</name></author>
	</entry>
	<entry>
		<id>https://wiki.universitas.ro/index.php?title=0421_-_Graf_Partial_1&amp;diff=8184&amp;oldid=prev</id>
		<title>Corjuc Eunice: Pagină nouă: = Cerinţa = Se dă lista muchiilor unui graf neorientat cu &lt;code&gt;n&lt;/code&gt; vârfuri, etichetate de la &lt;code&gt;1&lt;/code&gt; la &lt;code&gt;n&lt;/code&gt;. Din acest graf se elimină toate muchiile cu o extremitate de grad maxim și cealaltă extremitate de grad minim. Să se determine numărul de muchii eliminate și să se afișeze matricea de adiacență a grafului parțial obținut.  = Date de intrare = Fişierul de intrare &lt;code&gt;graf_partial_1.in&lt;/code&gt; conţine pe prima linie numărul &lt;cod...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0421_-_Graf_Partial_1&amp;diff=8184&amp;oldid=prev"/>
		<updated>2023-12-16T14:38:27Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: = Cerinţa = Se dă lista muchiilor unui graf neorientat cu &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; vârfuri, etichetate de la &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; la &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;. Din acest graf se elimină toate muchiile cu o extremitate de grad maxim și cealaltă extremitate de grad minim. Să se determine numărul de muchii eliminate și să se afișeze matricea de adiacență a grafului parțial obținut.  = Date de intrare = Fişierul de intrare &amp;lt;code&amp;gt;graf_partial_1.in&amp;lt;/code&amp;gt; conţine pe prima linie numărul &amp;lt;cod...&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 cu &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; vârfuri, etichetate de la &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; la &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;. Din acest graf se elimină toate muchiile cu o extremitate de grad maxim și cealaltă extremitate de grad minim. Să se determine numărul de muchii eliminate și să se afișeze matricea de adiacență a grafului parțial obținut.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fişierul de intrare &amp;lt;code&amp;gt;graf_partial_1.in&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;graf_partial_1.out&amp;lt;/code&amp;gt; va conţine pe prime linie numărul de muchii eliminate, iar pe următoarele linii matricea de adiacență a grafului parțial obținut, câte o linie a matricei pe o linie a fișierului, elementele de pe fiecare linie fiind separate prin exact un spațiu.&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;
* muchiile se pot repeta în fișierul de intrare&lt;br /&gt;
&lt;br /&gt;
== Exemplul 1 ==&lt;br /&gt;
graf_partial_1IN.txt:&lt;br /&gt;
&lt;br /&gt;
6&lt;br /&gt;
&lt;br /&gt;
1 3&lt;br /&gt;
&lt;br /&gt;
2 3&lt;br /&gt;
&lt;br /&gt;
2 4&lt;br /&gt;
&lt;br /&gt;
4 3&lt;br /&gt;
&lt;br /&gt;
5 3&lt;br /&gt;
&lt;br /&gt;
4 5&lt;br /&gt;
&lt;br /&gt;
3 1&lt;br /&gt;
&lt;br /&gt;
6 4&lt;br /&gt;
&lt;br /&gt;
graf_partial_1OUT.txt:&lt;br /&gt;
&lt;br /&gt;
2&lt;br /&gt;
&lt;br /&gt;
0 0 0 0 0 0&lt;br /&gt;
&lt;br /&gt;
0 0 1 1 0 0&lt;br /&gt;
&lt;br /&gt;
0 1 0 1 1 0&lt;br /&gt;
&lt;br /&gt;
0 1 1 0 1 0&lt;br /&gt;
&lt;br /&gt;
0 0 1 1 0 0&lt;br /&gt;
&lt;br /&gt;
0 0 0 0 0 0&lt;br /&gt;
&lt;br /&gt;
== Exemplul 2 ==&lt;br /&gt;
graf_partial_1IN.txt:&lt;br /&gt;
&lt;br /&gt;
999&lt;br /&gt;
&lt;br /&gt;
1 3&lt;br /&gt;
&lt;br /&gt;
2 3&lt;br /&gt;
&lt;br /&gt;
2 4&lt;br /&gt;
&lt;br /&gt;
4 3&lt;br /&gt;
&lt;br /&gt;
5 3&lt;br /&gt;
&lt;br /&gt;
4 5&lt;br /&gt;
&lt;br /&gt;
3 1&lt;br /&gt;
&lt;br /&gt;
6 4&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
Restrictiile nu sunt indeplinite.&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;
def check_input_restrictions(n, edges):&lt;br /&gt;
    if not (1 &amp;lt;= n &amp;lt;= 100):&lt;br /&gt;
        return False&lt;br /&gt;
&lt;br /&gt;
    for edge in edges:&lt;br /&gt;
        i, j = edge&lt;br /&gt;
        if not (1 &amp;lt;= i &amp;lt;= n) or not (1 &amp;lt;= j &amp;lt;= n):&lt;br /&gt;
            return False&lt;br /&gt;
&lt;br /&gt;
    return True&lt;br /&gt;
&lt;br /&gt;
def read_graph(filename):&lt;br /&gt;
    with open(filename, &amp;#039;r&amp;#039;) as file:&lt;br /&gt;
        n = int(file.readline())&lt;br /&gt;
        edges = [tuple(map(int, line.split())) for line in file.readlines()]&lt;br /&gt;
&lt;br /&gt;
    if not check_input_restrictions(n, edges):&lt;br /&gt;
        print(&amp;quot;Restrictiile nu sunt indeplinite.&amp;quot;)&lt;br /&gt;
        return None&lt;br /&gt;
&lt;br /&gt;
    return n, edges&lt;br /&gt;
def read_graph(filename):&lt;br /&gt;
    with open(filename, &amp;#039;r&amp;#039;) as file:&lt;br /&gt;
        n = int(file.readline())&lt;br /&gt;
        edges = [tuple(map(int, line.split())) for line in file.readlines()]&lt;br /&gt;
    return n, edges&lt;br /&gt;
&lt;br /&gt;
def write_output(filename, result):&lt;br /&gt;
    with open(filename, &amp;#039;w&amp;#039;) as file:&lt;br /&gt;
        file.write(str(result[&amp;#039;num_edges_removed&amp;#039;]) + &amp;#039;\n&amp;#039;)&lt;br /&gt;
        for row in result[&amp;#039;adjacency_matrix&amp;#039;]:&lt;br /&gt;
            file.write(&amp;#039; &amp;#039;.join(map(str, row)) + &amp;#039;\n&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
def build_adjacency_matrix(n, edges):&lt;br /&gt;
    adjacency_matrix = [[0] * n for _ in range(n)]&lt;br /&gt;
    for edge in edges:&lt;br /&gt;
        i, j = edge&lt;br /&gt;
        adjacency_matrix[i-1][j-1] = adjacency_matrix[j-1][i-1] = 1&lt;br /&gt;
    return adjacency_matrix&lt;br /&gt;
&lt;br /&gt;
def calculate_degrees(adjacency_matrix):&lt;br /&gt;
    degrees = [sum(row) for row in adjacency_matrix]&lt;br /&gt;
    return degrees&lt;br /&gt;
&lt;br /&gt;
def eliminate_edges(adjacency_matrix, degrees):&lt;br /&gt;
    max_degree = max(degrees)&lt;br /&gt;
    min_degree = min(degrees)&lt;br /&gt;
&lt;br /&gt;
    max_degree_nodes = [i for i in range(len(degrees)) if degrees[i] == max_degree]&lt;br /&gt;
    min_degree_nodes = [i for i in range(len(degrees)) if degrees[i] == min_degree]&lt;br /&gt;
    &lt;br /&gt;
    edges_removed = 0&lt;br /&gt;
    for i in max_degree_nodes:&lt;br /&gt;
        for j in min_degree_nodes:&lt;br /&gt;
            if adjacency_matrix[i][j] == 1:&lt;br /&gt;
                adjacency_matrix[i][j] = adjacency_matrix[j][i] = 0&lt;br /&gt;
                edges_removed += 1&lt;br /&gt;
&lt;br /&gt;
    return edges_removed&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    input_filename = &amp;quot;graf_partial_1IN.txt&amp;quot;&lt;br /&gt;
    output_filename = &amp;quot;graf_partial_1OUT.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    graph_data = read_graph(input_filename)&lt;br /&gt;
&lt;br /&gt;
    if graph_data is not None:&lt;br /&gt;
        n, edges = graph_data&lt;br /&gt;
&lt;br /&gt;
        adjacency_matrix = build_adjacency_matrix(n, edges)&lt;br /&gt;
        degrees = calculate_degrees(adjacency_matrix)&lt;br /&gt;
&lt;br /&gt;
        num_edges_removed = eliminate_edges(adjacency_matrix, degrees)&lt;br /&gt;
&lt;br /&gt;
        result = {&lt;br /&gt;
            &amp;#039;num_edges_removed&amp;#039;: num_edges_removed,&lt;br /&gt;
            &amp;#039;adjacency_matrix&amp;#039;: adjacency_matrix&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        write_output(output_filename, result)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Corjuc Eunice</name></author>
	</entry>
</feed>