We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def maximize_skillsets(s, w, people_skills, wizards_transformations):
# Start by creating a queue for BFS
queue = deque()
visited = set()
# Initialize the graph for transformations
graph = defaultdict(list)
# Build the graph for wizard transformations
for wizard in wizards_transformations:
list_A, list_B = wizard
for a in list_A:
for b in list_B:
graph[a-1].append(b-1)
graph[b-1].append(a-1)
# Add all current skill sets with people to the queue
for i in range(s):
if people_skills[i] > 0:
queue.append(i)
visited.add(i)
# Perform BFS to transform skills
while queue:
current_skill = queue.popleft()
for neighbor in graph[current_skill]:
if neighbor not in visited:
visited.add(neighbor)
people_skills[neighbor] += 1
queue.append(neighbor)
# Count the number of distinct skill sets with people
return sum(1 for count in people_skills if count > 0)
if name == "main":
# Reading input
s, w = map(int, input().split())
people_skills = list(map(int, input().split()))
wizards_transformations = []
for _ in range(w):
list_A = list(map(int, input().split()))[1:]
list_B = list(map(int, input().split()))[1:]
wizards_transformations.append((list_A, list_B))
My code is correct as its giving right output after running but failed 14/25 Test Cases
What is wrong in it, kindly help guys?
result = maximize_skillsets(s, w, people_skills, wizards_transformations)
print(result)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Training the army
You are viewing a single comment's thread. Return to all comments →
from collections import deque, defaultdict
def maximize_skillsets(s, w, people_skills, wizards_transformations): # Start by creating a queue for BFS queue = deque() visited = set()
if name == "main": # Reading input s, w = map(int, input().split()) people_skills = list(map(int, input().split()))
My code is correct as its giving right output after running but failed 14/25 Test Cases What is wrong in it, kindly help guys?