Lekcja – Graf kompletny
V1 = { 'A' : ['B', 'C', 'D'], 'B' : ['A', 'C', 'D'], 'C' : ['A', 'B', 'D'], 'D' : ['A', 'B', 'C'], } V2 = { 'A' : ['B', 'C', 'D'], 'B' : ['A', 'C', 'D'], 'C' : ['A', 'D'], 'D' : ['A', 'B', 'C'], } def is_complete(V): for n in V.keys(): if len(V[n]) != len(V) -1: return False return True print(f'Graph 1 - is_complete: {is_complete(V1)}') print(f'Graph 2 - is_complete: {is_complete(V2)}')
Lab
net = { 'Umbrella': ['Puddle','Drizzle', 'Storm', 'Rain'], 'Puddle': ['Umbrella','Drizzle', 'Storm', 'Rain'], 'Drizzle': ['Umbrella','Puddle', 'Storm', 'Rain'], 'Storm': ['Umbrella','Puddle', 'Drizzle', 'Rain'], 'Rain': ['Umbrella','Puddle', 'Drizzle', 'Storm'] } def is_complete(V): for n in V.keys(): if len(V[n]) != len(V) -1: return False return True print(f'is_complete: {is_complete(net)}') print(f'Number of spies {len(net)}') print(f'Number of meetings {len(net)*(len(net)-1)}')