Posts

Showing posts from September, 2020

Coloring of graph

 from random import randint #todo #chromatic number #currently supporting in max 4 color graph n=input("Enter Your vertex seprated by space:").split() vac={} for vertex in n: c=input(f"{vertex} is connected to? give value seprated by space:") vac[vertex]=c.split() CV=[] CG={} first=True for vertex in n: colors=["RED","GREEN","BLUE","YELLOW"] if first==True: first=False RC=colors[randint(0,len(colors)-1)] CG[vertex]=RC CV.append(vertex) continue temp2=vac[vertex] for conn in temp2: if conn in CG: CP=CG[conn] CI=colors.index(CP) colors.pop(CI) CG[vertex]=colors[randint(0,len(colors)-1)] CV.append(vertex) print(CG)

Java prac 2

  import java.util.*; class Main  { public static void main (String[] args) throws java.lang.Exception {     Scanner scan=new Scanner(System.in);     System.out.println("Enter The Number of Rows:");     int n=scan.nextInt();     System.out.println("Enter the number of Cols:");     int m=scan.nextInt();     int[][] array=new int[n][m];     for(int i=0;i<n;i++){       System.out.println("Give The Values of row "+(i+1)+":");       for(int j=0;j<m;j++){       System.out.println("Give The Value of col "+(j+1)+":");       array[i][j]=scan.nextInt();       }     }     System.out.println("Array is Having ");     for(int i=0;i<n;i++){       System.out.println();       for(int j=0;j<m;j++){         System.out.print(array[i][j]+" ");   ...