from collections import defaultdict, deque
def min_energy(n, t_input, s, d):
g = defaultdict(list)
t_map = {}
t_id = 0
for line in t_input:
if line == "break":
t_id += 1
continue
spots = list(map(int, line.split()))
p = spots[0]
for c in spots[1:]:
g[p].append(c)
t_map[c] = t_id
e_cost = {}
q = deque([(s, 0)])
e_cost[s] = 0
while q:
cur, cur_e = q.popleft()
if cur == d:
return cur_e
for c in g[cur]:
if c not in e_cost or cur_e + 1 < e_cost[c]:
e_cost[c] = cur_e + 1
q.append((c, cur_e + 1))
for neighbor in g:
if neighbor != cur and neighbor in e_cost:
e_next = cur_e + 1
if neighbor not in e_cost or e_next < e_cost[neighbor]:
e_cost[neighbor] = e_next
q.append((neighbor, e_next))
return float('inf')
n = int(input())
t_input = []
for _ in range(n):
t_input.append(input().strip())
s, d = map(int, input().split())
result = min_energy(n, t_input, s, d)
print(result)
Hybrid banana ✓ // codevita ✓
def min_energy(n, t_input, s, d):
g = defaultdict(list)
t_map = {}
t_id = 0
for line in t_input:
if line == "break":
t_id += 1
continue
spots = list(map(int, line.split()))
p = spots[0]
for c in spots[1:]:
g[p].append(c)
t_map[c] = t_id
e_cost = {}
q = deque([(s, 0)])
e_cost[s] = 0
while q:
cur, cur_e = q.popleft()
if cur == d:
return cur_e
for c in g[cur]:
if c not in e_cost or cur_e + 1 < e_cost[c]:
e_cost[c] = cur_e + 1
q.append((c, cur_e + 1))
for neighbor in g:
if neighbor != cur and neighbor in e_cost:
e_next = cur_e + 1
if neighbor not in e_cost or e_next < e_cost[neighbor]:
e_cost[neighbor] = e_next
q.append((neighbor, e_next))
return float('inf')
n = int(input())
t_input = []
for _ in range(n):
t_input.append(input().strip())
s, d = map(int, input().split())
result = min_energy(n, t_input, s, d)
print(result)
Hybrid banana ✓ // codevita ✓
successfully offline infosys Help Done ✅
From imneo ✓
Infosys Sp( Trainee-9.5 Lpa)✅
Test accomplished ❤️ || Offcampus ✓
Test accomplished
All placement help available
DM @MRTRUELIVING_IX
@MRTRUELIVING_IX
#Infosys #Sp #offline #imneo✓
Please open Telegram to view this post
VIEW IN TELEGRAM
Successfully Help done Virtusa ( Hackthon)
Role : SDET
DM for any placement Help
@Mrtrueliving_ix @Mrtrueliving_ix
#Virtusa #Hackthon #Offcampus #SDT
Test accomplished ❤️ || All sections are completed 🔸🎉
Virtusa - Java Help Done ✅
Test accomplished ❤️ || Offcampus ✓
DM for any placement Help
@Mrtrueliving_ix @Mrtrueliving_ix
#Virtusa #Java #Offcampus #R1
Please open Telegram to view this post
VIEW IN TELEGRAM
Viasat ONCAMPUS Help done ✅
Test accomplished ❤️ || ONCAMPUS
DM for any placement Help
@Mrtrueliving_ix @Mrtrueliving_ix
#Viasat #ONCAMPUS #R1
All sections Are done with coding 💞
Virtusa Hackthon - 2pm All codes are available
DM @Mrtrueliving_ix
Plagfree coding || Verified codes Only
Virtusa // QA Help done { only Coding}
Test accomplished ❤️ || Offcampus
DM for all placement help
@Mrtrueliving_ix @Mrtrueliving_ix
#Virtusa #QA #Offcampus
Please open Telegram to view this post
VIEW IN TELEGRAM