Beta

Coping with NP-Hardness #2: Max Weight Independent Set of a Tree

Description:

You have been tasked with generated an invite list for your christmas office party. You know several things:

  • You want to have the most fun party possible.
  • Every person invited to your party grants your party some level of person-dependent fun. Anna, being a jerk, grants your party only +3 fun points, while Jane, being a TOTAL BADASS, grants your party +999 fun points.
  • If any employee comes into contact with his/her boss, the two will fight, ruining the party for everyone. Think of that as a -infinity fun value.
  • Each person has at most 1 boss. Each boss has at most infinite employees. There are no circular arrangements of bosses, such as Jane is Bill's boss, Bill is Adam's boss, and Adam is Jane's boss: your company has a strict dominance heirarchy.
  • All given employees are from a single division of the company, meaning that they are all somehow connected to one another.
  • You have absolute freedom in who you decide to invite. If your boss or the head honcho aren't invited, they won't care, they'll be happy knowing the plebs are having fun.

Given the above criteria, you must find some subset of employees that, when brought together, will have the

BEST RAGER EVER.

Inputs are dictionaries containing boss-to-employees relationships, in the format '{name_string: list_of_employee_names}', and dictionaries of fun values, in the format '{name_string: fun_value}'.

Output is a lists of the names of your chosen subset of people. Your output will be checked to ensure that no contained people are in a boss-employee relationship and that the sum of their values is greater than or equal to the sum of the values of the baseline solution's answer.

Note: The boss->employee dictionary might not contain all company members.

Kata in this Series

  1. Coping with NP-Hardness #1: 2-SAT
  2. Coping with NP-Hardness #2: Max Weight Independent Set of a Tree
  3. Coping with NP-Hardness #3: Finding the Minimum Hamiltonian Cycle
  4. Coping with NP-Hardness #4: 3-Recoloring
Algorithms

More By Author:

Check out these other kata created by ALowVerus

Stats:

CreatedJun 9, 2020
PublishedJun 10, 2020
Warriors Trained32
Total Skips0
Total Code Submissions96
Total Times Completed6
Python Completions6
Total Stars0
% of votes with a positive feedback rating50% of 1
Total "Very Satisfied" Votes0
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes0
Ad
Contributors
  • ALowVerus Avatar
Ad