<?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=1652_-_RF</id>
	<title>1652 - RF - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=1652_-_RF"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1652_-_RF&amp;action=history"/>
	<updated>2026-05-01T04:46:11Z</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=1652_-_RF&amp;diff=10069&amp;oldid=prev</id>
		<title>Danciu: Pagină nouă:  = Cerința = Se dă un graf orientat în care arcele au asociate costuri (numere naturale nenule). Să se determine câte arce &lt;code&gt;(x,y)&lt;/code&gt; din graf au costul egal cu costul drumului de cost minim de la &lt;code&gt;x&lt;/code&gt; la &lt;code&gt;y&lt;/code&gt;.  = Date de intrare = Programul citește de la tastatură numerele &lt;code&gt;n m&lt;/code&gt;, reprezentând numărul de vârfuri și numărul de arce din graf, apoi &lt;code&gt;m&lt;/code&gt; triplete &lt;code&gt;i j p&lt;/code&gt;, reprezentând arcele, date prin extre...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1652_-_RF&amp;diff=10069&amp;oldid=prev"/>
		<updated>2024-06-03T22:35:12Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă:  = Cerința = Se dă un graf orientat în care arcele au asociate costuri (numere naturale nenule). Să se determine câte arce &amp;lt;code&amp;gt;(x,y)&amp;lt;/code&amp;gt; din graf au costul egal cu costul drumului de cost minim de la &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; la &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt;.  = Date de intrare = Programul citește de la tastatură numerele &amp;lt;code&amp;gt;n m&amp;lt;/code&amp;gt;, reprezentând numărul de vârfuri și numărul de arce din graf, apoi &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt; triplete &amp;lt;code&amp;gt;i j p&amp;lt;/code&amp;gt;, reprezentând arcele, date prin extre...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
= Cerința =&lt;br /&gt;
Se dă un graf orientat în care arcele au asociate costuri (numere naturale nenule). Să se determine câte arce &amp;lt;code&amp;gt;(x,y)&amp;lt;/code&amp;gt; din graf au costul egal cu costul drumului de cost minim de la &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; la &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Programul citește de la tastatură numerele &amp;lt;code&amp;gt;n m&amp;lt;/code&amp;gt;, reprezentând numărul de vârfuri și numărul de arce din graf, apoi &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt; triplete &amp;lt;code&amp;gt;i j p&amp;lt;/code&amp;gt;, reprezentând arcele, date prin extremități și cost.&lt;br /&gt;
&lt;br /&gt;
= Date de ieșire =&lt;br /&gt;
Programul va afișa pe ecran numărul &amp;lt;code&amp;gt;C&amp;lt;/code&amp;gt;, reprezentând valoare cerută.&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;
* costurile arcelor vor fi mai mici decât &amp;lt;code&amp;gt;1000&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Exemplu: =&lt;br /&gt;
Intrare&lt;br /&gt;
 5 7&lt;br /&gt;
 2 1 10&lt;br /&gt;
 2 3 2&lt;br /&gt;
 3 1 10&lt;br /&gt;
 3 4 3&lt;br /&gt;
 3 5 1&lt;br /&gt;
 4 1 2&lt;br /&gt;
 5 4 1&lt;br /&gt;
Ieșire&lt;br /&gt;
 4&lt;br /&gt;
&lt;br /&gt;
=== Explicație ===&lt;br /&gt;
Cele &amp;lt;code&amp;gt;4&amp;lt;/code&amp;gt; arce sunt: &amp;lt;code&amp;gt;(2 3)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;(3 5)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;(4 1)&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;(5 4)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Rezolvare ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def floyd_warshall(n, dist):&lt;br /&gt;
    for k in range(n):&lt;br /&gt;
        for i in range(n):&lt;br /&gt;
            for j in range(n):&lt;br /&gt;
                if dist[i][k] + dist[k][j] &amp;lt; dist[i][j]:&lt;br /&gt;
                    dist[i][j] = dist[i][k] + dist[k][j]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    n, m = map(int, input().split())&lt;br /&gt;
&lt;br /&gt;
    inf = float(&amp;#039;inf&amp;#039;)&lt;br /&gt;
    dist = [[inf] * n for _ in range(n)]&lt;br /&gt;
&lt;br /&gt;
    edges = []&lt;br /&gt;
    for _ in range(m):&lt;br /&gt;
        u, v, p = map(int, input().split())&lt;br /&gt;
        u -= 1&lt;br /&gt;
        v -= 1&lt;br /&gt;
        dist[u][v] = p&lt;br /&gt;
        edges.append((u, v, p))&lt;br /&gt;
&lt;br /&gt;
    for i in range(n):&lt;br /&gt;
        dist[i][i] = 0&lt;br /&gt;
&lt;br /&gt;
    floyd_warshall(n, dist)&lt;br /&gt;
&lt;br /&gt;
    count = 0&lt;br /&gt;
    for u, v, p in edges:&lt;br /&gt;
        if dist[u][v] == p:&lt;br /&gt;
            count += 1&lt;br /&gt;
&lt;br /&gt;
    print(count)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Danciu</name></author>
	</entry>
</feed>