
'''simple docstring'''



from collections import defaultdict




class   UpperCAmelCase_			:






						'''simple docstring'''






						def __init__( self   ,       _lowercase   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			total  # total no of tasks (N)

												# DP table will have a dimension of (2^M)*N
												# initially all values are set to -1
												_lowerCAmelCase  						=			[
												    [-1 for i in range(total + 1				)] for j in range(2 ** len(SCREAMING_SNAKE_CASE_				)				)
												]

												_lowerCAmelCase  						=			defaultdict(SCREAMING_SNAKE_CASE_				)  # stores the list of persons for each task

												# final_mask is used to check if all persons are included by setting all bits
												# to 1
												_lowerCAmelCase  						=			(1 << len(SCREAMING_SNAKE_CASE_				)) - 1




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase				):

												"""simple docstring"""



												if mask == self.final_mask:
																		return 1

												# if not everyone gets the task and no more tasks are available, return 0
												if task_no > self.total_tasks:
																		return 0

												# if case already considered
												if self.dp[mask][task_no] != -1:
																		return self.dp[mask][task_no]

												# Number of ways when we don't this task in the arrangement
												_lowerCAmelCase  						=			self.count_ways_until(SCREAMING_SNAKE_CASE_   ,       task_no + 1				)

												# now assign the tasks one by one to all possible persons and recursively
												# assign for the remaining tasks.
												if task_no in self.task:
																		for p in self.task[task_no]:
																								# if p is already given a task
																								if mask & (1 << p):
																														continue

																								# assign this task to p and change the mask value. And recursively
																								# assign tasks with the new mask value.
																								total_ways_util += self.count_ways_until(mask | (1 << p)   ,       task_no + 1				)

        # save the value.
												_lowerCAmelCase  						=			total_ways_util

												return self.dp[mask][task_no]




						def  _lowercase     ( self   ,       _lowercase				):

												"""simple docstring"""



												for i in range(len(SCREAMING_SNAKE_CASE_				)				):
																		for j in task_performed[i]:
																								self.task[j].append(SCREAMING_SNAKE_CASE_				)

        # call the function to fill the DP table, final answer is stored in dp[0][1]
												return self.count_ways_until(0   ,       1				)


if __name__ == "__main__":
						_lowercase    =		5  # total no of tasks (the value of N)

						# the list of tasks that can be done by M persons.
						_lowercase    =		[[1, 3, 4], [1, 2, 5], [3, 4]]
						print(
						    AssignmentUsingBitmask(task_performed, total_tasks).count_no_of_ways(
						        task_performed
						    )
						)


'''simple docstring'''



import heapq as hq
import math
from collections.abc import Iterator




class   UpperCAmelCase_					:






						'''simple docstring'''






						def __init__( self   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			str(id_				)
												_lowerCAmelCase  						=			None
												_lowerCAmelCase  						=			None
												_lowerCAmelCase  						=			[]
												_lowerCAmelCase  						=			{}  # {vertex:distance}




						def __lt__( self   ,       _lowercase				):

												"""simple docstring"""



												return self.key < other.key




						def __repr__( self				):

												"""simple docstring"""



												return self.id




						def  _lowercase     ( self   ,       _lowercase				):

												"""simple docstring"""



												self.neighbors.append(_lowercase				)




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			weight






def A				(__lowerCamelCase				:List[Any]			,     __lowerCamelCase				:Union[str, Any]			,     __lowerCamelCase				:Dict			,     __lowerCamelCase				:Optional[int]		):
						# add the neighbors:
						graph[a - 1].add_neighbor(graph[b - 1]		)
						graph[b - 1].add_neighbor(graph[a - 1]		)
						# add the edges:
						graph[a - 1].add_edge(graph[b - 1]			,     __lowerCamelCase		)
						graph[b - 1].add_edge(graph[a - 1]			,     __lowerCamelCase		)


def A				(__lowerCamelCase				:list			,     __lowerCamelCase				:Vertex		):
						_lowerCAmelCase  						=			[]
						for u in graph:
												_lowerCAmelCase  						=			math.inf
												_lowerCAmelCase  						=			None
						_lowerCAmelCase  						=			0
						_lowerCAmelCase  						=			graph[:]
						while q:
												_lowerCAmelCase  						=			min(__lowerCamelCase		)
												q.remove(__lowerCamelCase		)
												for v in u.neighbors:
																		if (v in q) and (u.edges[v.id] < v.key):
																								_lowerCAmelCase  						=			u
																								_lowerCAmelCase  						=			u.edges[v.id]
						for i in range(1			,     len(__lowerCamelCase		)		):
												a.append((int(graph[i].id		) + 1, int(graph[i].pi.id		) + 1)		)
						return a


def A				(__lowerCamelCase				:list			,     __lowerCamelCase				:Vertex		):
						for u in graph:
												_lowerCAmelCase  						=			math.inf
												_lowerCAmelCase  						=			None
						_lowerCAmelCase  						=			0

						_lowerCAmelCase  						=			list(__lowerCamelCase		)
						hq.heapify(__lowerCamelCase		)

						while h:
												_lowerCAmelCase  						=			hq.heappop(__lowerCamelCase		)
												for v in u.neighbors:
																		if (v in h) and (u.edges[v.id] < v.key):
																								_lowerCAmelCase  						=			u
																								_lowerCAmelCase  						=			u.edges[v.id]
																								hq.heapify(__lowerCamelCase		)

						for i in range(1			,     len(__lowerCamelCase		)		):
												yield (int(graph[i].id		) + 1, int(graph[i].pi.id		) + 1)


def A				():
						pass


if __name__ == "__main__":
						import doctest

						doctest.testmod()
