from collections import defaultdict graph=defaultdict(list) v,e=map(int,input().split()) for i in range(e): u,v=map(str,input().split()) graph[u].append(v) graph[v].append(u) for i in graph: print(i,"->",graph[i]) Input: 7 9 A B A C A F C E C F C D D E D G G F Output: F -> ['A', 'C', 'G'] C -> ['A', 'E', 'F', 'D'] G -> ['D', 'F'] D -> ['C', 'E', 'G'] A -> ['B', 'C', 'F'] E -> ['C', 'D'] B -> ['A']
#
#lets see n=7
#count =0
#in binary 7 is 111 =>7 count =1
#in binary 6 is 101
#
#so bitwise & = 101 =>6 count =2
#in binary 6 is 101
#in binary 5 is 100
#
#so bitwise & = 100 =>5 count =3
#in binary 5 is 100
#in binary 4 is 011
#
#so bitwise & = 000 =>0
def onces(n):
cnt=0
while(n):
cnt+=1
n=n&(n-1)
return cnt
n=int(input())
print("Onces in ",bin(n)[2:],"is",onces(n))
Comments
Post a Comment