<?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=0643_%E2%80%93_Det_Drum1</id>
	<title>0643 – Det Drum1 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=0643_%E2%80%93_Det_Drum1"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0643_%E2%80%93_Det_Drum1&amp;action=history"/>
	<updated>2026-06-19T09:15:01Z</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=0643_%E2%80%93_Det_Drum1&amp;diff=8851&amp;oldid=prev</id>
		<title>Corjuc Eunice: Pagină nouă: = Cerința = Se dă vectorul de tați al unui arbore cu rădăcină cu &lt;code&gt;n&lt;/code&gt; noduri și un nod &lt;code&gt;k&lt;/code&gt;. Determinați drumul de la rădăcina arborelui la nodul &lt;code&gt;k&lt;/code&gt;.  = Date de intrare = Fișierul de intrare &lt;code&gt;detdrum1IN.txt&lt;/code&gt; conține pe prima linie numărul de noduri &lt;code&gt;n&lt;/code&gt; și nodul &lt;code&gt;k&lt;/code&gt;. Pe linia următoare se află vectorul de tați al arborelui, valorile fiind separate prin spații.  = Date de ieșire = Fișierul de i...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0643_%E2%80%93_Det_Drum1&amp;diff=8851&amp;oldid=prev"/>
		<updated>2024-01-03T14:48:00Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: = Cerința = Se dă vectorul de tați al unui arbore cu rădăcină cu &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; noduri și un nod &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;. Determinați drumul de la rădăcina arborelui la nodul &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;.  = Date de intrare = Fișierul de intrare &amp;lt;code&amp;gt;detdrum1IN.txt&amp;lt;/code&amp;gt; conține pe prima linie numărul de noduri &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; și nodul &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;. Pe linia următoare se află vectorul de tați al arborelui, valorile fiind separate prin spații.  = Date de ieșire = Fișierul de i...&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ă vectorul de tați al unui arbore cu rădăcină cu &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; noduri și un nod &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;. Determinați drumul de la rădăcina arborelui la nodul &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fișierul de intrare &amp;lt;code&amp;gt;detdrum1IN.txt&amp;lt;/code&amp;gt; conține pe prima linie numărul de noduri &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; și nodul &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;. Pe linia următoare se află vectorul de tați al arborelui, valorile fiind separate prin spații.&lt;br /&gt;
&lt;br /&gt;
= Date de ieșire =&lt;br /&gt;
Fișierul de ieșire &amp;lt;code&amp;gt;detdrum1OUT.txt&amp;lt;/code&amp;gt; va conține pe prima linie nodurile care alcătuiesc drumul determinat, separate printr-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 ≤ k ≤ n&amp;lt;/code&amp;gt;&lt;br /&gt;
* în vectorul de tați rădăcina este marcată cu &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exemplul 1 ==&lt;br /&gt;
detdrum1IN.txt:&lt;br /&gt;
&lt;br /&gt;
7 2&lt;br /&gt;
&lt;br /&gt;
4 1 7 0 7 7 1&lt;br /&gt;
&lt;br /&gt;
detdrum1OUT.txt:&lt;br /&gt;
&lt;br /&gt;
4 1 2&lt;br /&gt;
&lt;br /&gt;
== Exemplul 2 ==&lt;br /&gt;
detdrum1IN.txt:&lt;br /&gt;
&lt;br /&gt;
101 2&lt;br /&gt;
&lt;br /&gt;
4 1 7 0 7 7 1&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
Invalid input. Please check the conditions.&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 is_valid_input(n, k):&lt;br /&gt;
    return 1 &amp;lt;= n &amp;lt;= 100 and 1 &amp;lt;= k &amp;lt;= n&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;detdrum1IN.txt&amp;quot;, &amp;quot;r&amp;quot;) as infile, open(&amp;quot;detdrum1OUT.txt&amp;quot;, &amp;quot;w&amp;quot;) as outfile:&lt;br /&gt;
    n, k = map(int, infile.readline().split())&lt;br /&gt;
&lt;br /&gt;
    if not is_valid_input(n, k):&lt;br /&gt;
        print(&amp;quot;Invalid input. Please check the conditions.&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        t = [0] + list(map(int, infile.readline().split()))&lt;br /&gt;
&lt;br /&gt;
        def detdrum(nod):&lt;br /&gt;
            if nod == 0:&lt;br /&gt;
                return&lt;br /&gt;
            detdrum(t[nod])&lt;br /&gt;
            outfile.write(str(nod) + &amp;quot; &amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        detdrum(k)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Corjuc Eunice</name></author>
	</entry>
</feed>