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=6
#
#in binary 6 is 101 =>6
#lets check at 1 from right
# 1<<(1-1) => its left shift so it multiplies 1 with 2**(1-1) thats 2**0
# so 2**0 is 1
#1*1=>1
#in binary 6 is 101
#in binary 1 is 001
#
#so bitwise & = 001 =>1 SET
#
# Ex2
#In binary 6 is 101 =>6
#lets check at 2 from right
# 1<<(2-1) => its left shift so it multiplies 1 with 2**(2-1) thats 2**1
# so 2**1 is 2
#1*2=>2
#in binary 6 is 101
#in binary 1 is 010
#
#so bitwise & = 000 =>0 NOT SET
def kthbit(n,k):
if n&(1<<(k-1)):
print("SET")
else:
print("Not Set")
n,k=map(int,input().split())
print("The bit in ",bin(n)[2:],"at",k,"from right is")
kthbit(n,k)
Comments
Post a Comment