Question: 0 : r e d , 1 : b l u e , 2 : g r e e n 2 c o s t

0 : r e d ,1 : b l u e ,2 : g r e e n
2 c o s t s =[[18,3,18],[14,14,4],[15,3,17]]
3 # c o s t s [1][2] : c o s t o f p a i n t i n g node 1 c o l o r g r e e n
4 # t o t a l number o f c o m b i n a t i o n s : n u m b e r c o l o r s n u m b e r h o u s e s =33=27
5 # e n u m e r a t e d l i s t o f f e a s i b l e c o m b i n a t i o n s (12) : [[0,1,0],[0,1,2],[0,2,0],[0,2,1],[1,0,
1],[1,0,2],[1,2,0],[1,2,1],[2,0,1],[2,0,2],[2,1,0],[2,1,2]]
6 # [0,1,0] : f e a s i b l e b e c a u s e a l l a d j a c e n t n o d e s h a v e d i f f e r e n t c o l o r
7 # [0,1,1] : n o t f e a s i b l e b e c a u s e l a s t 2 n o d e s h a v e same c o l o r
8 # H i n t : i t e r t o o l s . p r o d u c t () l i b r a r y f u n c t i o n g e n e r a t e s a l l 27 c o m b i n a t i o n s
9
10 m i n c o s t e n u m , b e s t c o l o r i n g e n u m = m i n c o s t v e r t e x c o l o r i n g e n u m e r a t i o n ( c o s t s )
11 # m i n c o s t e n u m : 10, b e s t c o l o r i n g e n u m : [1,2,1]
keeping this sample function call and expected inputs/outputs write the python code as a python script

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!