<?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=2933_-_TollRoads</id>
	<title>2933 - TollRoads - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=2933_-_TollRoads"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=2933_-_TollRoads&amp;action=history"/>
	<updated>2026-05-01T06:50:24Z</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=2933_-_TollRoads&amp;diff=10084&amp;oldid=prev</id>
		<title>Danciu: Pagină nouă:  = Cerința = &lt;code&gt;N&lt;/code&gt; orașe sunt conectate între ele prin &lt;code&gt;M&lt;/code&gt; autostrăzi bidirecționale, fiecare autostradă &lt;code&gt;(a, b)&lt;/code&gt; având un cost de tranzit &lt;code&gt;c&lt;/code&gt; atașat. Se dorește revizuirea sistemului de taxare, însă sunt câteva aspecte ce trebuie luate în calcul și necesită investigație, deoarece o parte dintre cele &lt;code&gt;N&lt;/code&gt; orașe sunt centre comerciale sau turistice importante.  Se dorește să se afle răspunsul la o serie de...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=2933_-_TollRoads&amp;diff=10084&amp;oldid=prev"/>
		<updated>2024-06-04T03:00:30Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă:  = Cerința = &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; orașe sunt conectate între ele prin &amp;lt;code&amp;gt;M&amp;lt;/code&amp;gt; autostrăzi bidirecționale, fiecare autostradă &amp;lt;code&amp;gt;(a, b)&amp;lt;/code&amp;gt; având un cost de tranzit &amp;lt;code&amp;gt;c&amp;lt;/code&amp;gt; atașat. Se dorește revizuirea sistemului de taxare, însă sunt câteva aspecte ce trebuie luate în calcul și necesită investigație, deoarece o parte dintre cele &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; orașe sunt centre comerciale sau turistice importante.  Se dorește să se afle răspunsul la o serie de...&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;
&amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; orașe sunt conectate între ele prin &amp;lt;code&amp;gt;M&amp;lt;/code&amp;gt; autostrăzi bidirecționale, fiecare autostradă &amp;lt;code&amp;gt;(a, b)&amp;lt;/code&amp;gt; având un cost de tranzit &amp;lt;code&amp;gt;c&amp;lt;/code&amp;gt; atașat. Se dorește revizuirea sistemului de taxare, însă sunt câteva aspecte ce trebuie luate în calcul și necesită investigație, deoarece o parte dintre cele &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; orașe sunt centre comerciale sau turistice importante.&lt;br /&gt;
&lt;br /&gt;
Se dorește să se afle răspunsul la o serie de &amp;lt;code&amp;gt;Q&amp;lt;/code&amp;gt; întrebări de forma: &amp;lt;code&amp;gt;(X, T)&amp;lt;/code&amp;gt; – câte dintre celelalte &amp;lt;code&amp;gt;N-1&amp;lt;/code&amp;gt; orașe au acces către orașul &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt;, cu o taxă totală de cel mult &amp;lt;code&amp;gt;T&amp;lt;/code&amp;gt; către fiecare oraș?&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fișierul de intrare &amp;lt;code&amp;gt;tollroads.in&amp;lt;/code&amp;gt; conține pe primul rând numerele &amp;lt;code&amp;gt;N, M și Q&amp;lt;/code&amp;gt; reprezentând numărul de orașe, numărul de autostrăzi și numărul de interogări. Pe fiecare din următoarele &amp;lt;code&amp;gt;M&amp;lt;/code&amp;gt; rânduri sunt scrise câte trei numere &amp;lt;code&amp;gt;a, b, c,&amp;lt;/code&amp;gt; separate prin câte un spațiu, reprezentând două orașe între care există o autostradă și costul autostrăzii. Pe următoarele &amp;lt;code&amp;gt;Q&amp;lt;/code&amp;gt; rânduri se află scrise câte două numere &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt; și &amp;lt;code&amp;gt;T&amp;lt;/code&amp;gt;, separate prin spațiu, reprezentând datele interogărilor, conform enunțului.&lt;br /&gt;
&lt;br /&gt;
= Date de ieșire =&lt;br /&gt;
În fișierul de ieșire &amp;lt;code&amp;gt;tollroads.out&amp;lt;/code&amp;gt; se vor scrie pe fiecare dintre primele &amp;lt;code&amp;gt;Q&amp;lt;/code&amp;gt; rânduri câte un singur număr, reprezentând răspunsurile la interogări, în ordinea în care ele au fost puse.&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.000&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ M ≤ 100.000&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ a, b ≤ N&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ c ≤ 100.000&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ T ≤ 100.000&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ Q ≤ 100&amp;lt;/code&amp;gt;&lt;br /&gt;
* între orice două orașe poate exista mai mult de o autostrada&lt;br /&gt;
&lt;br /&gt;
= Exemplu: =&lt;br /&gt;
&amp;lt;code&amp;gt;tollroads.in&amp;lt;/code&amp;gt;&lt;br /&gt;
 7 8 5&lt;br /&gt;
 1 2 1&lt;br /&gt;
 2 3 2&lt;br /&gt;
 2 4 4&lt;br /&gt;
 3 5 1&lt;br /&gt;
 4 5 1&lt;br /&gt;
 5 6 2&lt;br /&gt;
 1 6 5&lt;br /&gt;
 6 7 1&lt;br /&gt;
 1 6&lt;br /&gt;
 1 5&lt;br /&gt;
 1 4&lt;br /&gt;
 2 3&lt;br /&gt;
 4 4&lt;br /&gt;
&amp;lt;code&amp;gt;tollroads.out&amp;lt;/code&amp;gt;&lt;br /&gt;
 6&lt;br /&gt;
 5&lt;br /&gt;
 3&lt;br /&gt;
 3&lt;br /&gt;
 5&lt;br /&gt;
&lt;br /&gt;
=== Explicație ===&lt;br /&gt;
Orașele &amp;lt;code&amp;gt;2,3,4,5,6,7&amp;lt;/code&amp;gt; au acces către orașul &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; cu taxă maximă &amp;lt;code&amp;gt;6&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Orașele &amp;lt;code&amp;gt;2,3,4,5,6&amp;lt;/code&amp;gt; au acces către orașul &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; cu taxă maximă &amp;lt;code&amp;gt;5&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Orașele &amp;lt;code&amp;gt;2,3,5&amp;lt;/code&amp;gt; au acces către orașul &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; cu taxă maximă &amp;lt;code&amp;gt;4&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Orașele &amp;lt;code&amp;gt;1,3,5&amp;lt;/code&amp;gt; au acces către orașul &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; cu taxă maximă &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Orașele &amp;lt;code&amp;gt;2,3,5,6,7&amp;lt;/code&amp;gt; au acces către orașul &amp;lt;code&amp;gt;4&amp;lt;/code&amp;gt; cu taxă maximă &amp;lt;code&amp;gt;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;
from collections import defaultdict, deque&lt;br /&gt;
&lt;br /&gt;
INF = 2000000002&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    f = open(&amp;quot;tollroads.in&amp;quot;, &amp;quot;r&amp;quot;)&lt;br /&gt;
    g = open(&amp;quot;tollroads.out&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    n, m, Q = map(int, f.readline().split())&lt;br /&gt;
&lt;br /&gt;
    graph = defaultdict(list)&lt;br /&gt;
    for _ in range(m):&lt;br /&gt;
        x, y, c = map(int, f.readline().split())&lt;br /&gt;
        graph[x].append((y, c))&lt;br /&gt;
        graph[y].append((x, c))&lt;br /&gt;
&lt;br /&gt;
    for _ in range(Q):&lt;br /&gt;
        nod, taxa = map(int, f.readline().split())&lt;br /&gt;
        dr = [INF] * (n + 1)&lt;br /&gt;
        din = [[] for _ in range(taxa + 1)]&lt;br /&gt;
&lt;br /&gt;
        din[0].append(nod)&lt;br /&gt;
        dr[nod] = sol = 0&lt;br /&gt;
&lt;br /&gt;
        viz = [False] * (n + 1)&lt;br /&gt;
&lt;br /&gt;
        for i in range(taxa + 1):&lt;br /&gt;
            for nod in din[i]:&lt;br /&gt;
                if viz[nod]:&lt;br /&gt;
                    continue&lt;br /&gt;
                for ve, co in graph[nod]:&lt;br /&gt;
                    if dr[nod] + co &amp;gt; taxa or viz[ve]:&lt;br /&gt;
                        continue&lt;br /&gt;
                    if dr[ve] &amp;gt; dr[nod] + co:&lt;br /&gt;
                        dr[ve] = dr[nod] + co&lt;br /&gt;
                        din[dr[ve]].append(ve)&lt;br /&gt;
                viz[nod] = True&lt;br /&gt;
            din[i] = []&lt;br /&gt;
&lt;br /&gt;
        for i in range(1, n + 1):&lt;br /&gt;
            viz[i] = False&lt;br /&gt;
            if dr[i] != INF:&lt;br /&gt;
                sol += 1&lt;br /&gt;
        &lt;br /&gt;
        g.write(str(sol - 1) + &amp;#039;\n&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
    f.close()&lt;br /&gt;
    g.close()&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>Danciu</name></author>
	</entry>
</feed>