NP-Complete: First working version

This commit is contained in:
2025-12-07 18:00:19 -05:00
parent d3e7ce3189
commit 0dab59e81e
4 changed files with 160 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
"""
name: Nicholas Tamassia
Honor Code and Acknowledgments:
This work complies with the JMU Honor Code.
Comments here on your code and submission.
"""
def independent_set(proposed_set: set[int], graph: dict[int, set[int]]) -> bool:
for vertex in proposed_set:
for adjecent in graph[vertex]:
if adjecent in proposed_set:
return False
return True
# All modules for CS 412 must include a main method that allows it
# to imported and invoked from other python scripts
def main():
n = int(input())
graph: dict[int, set[int]] = {}
for _ in range(n):
vertecies = list(map(int, input().split()))
graph[vertecies[0]] = set(vertecies[1:])
proposed_set = set(map(int, input().split()))
print("TRUE" if independent_set(proposed_set, graph) else "FALSE")
if __name__ == "__main__":
main()