- 1

Graphs

Help I can't figure this one out. You are making a social network called X. Connections between the users are stored as a graph. The given code declares an X class with its add_friend() method and creates some connections for 5 users. class X(): def __init__(self, size): self.adj = [ [0] * size for i in range(size)] self.size = size def add_friend(self, x, y): if x > self.size or y > self.size or x < 0 or y < 0: print("Error") else: self.adj[x-1][y-1] = 1 self.adj[y-1][x-1] = 1 def remove_friend(self, x, y): if x > self.size or y > self.size or x < 0 or y < 0: print("Error") else: self.adj[x-1][y-1] = 0 self.adj[y-1][x-1] = 0 def display(self): for row in self.adj: print() x = X(5) x.add_friend(1, 3) x.add_friend(1, 5) x.add_friend(2, 5) x.add_friend(2, 4) x.add_friend(4, 5) n = int(input()) #your code goes here n= X(n) print(n)

14th Sep 2021, 9:48 PM
ismail teke
ismail teke - avatar
3 ответов
+ 3
I hate this. I'm also looking for answer.
8th May 2022, 9:11 AM
Faisal Pangestu
Faisal Pangestu - avatar
+ 2
Is this a PRO challenge? if it is, then I suggest you to include the task in your thread's Description because non PRO users can't view the task to understand it.
15th Sep 2021, 3:35 AM
Ipang
+ 1
#your code goes here num = 0 for row in range (len(x.adj)): if row+1==n: for col in x.adj[row]: if col==1: num += 1 print(num)
8th Jun 2022, 4:27 AM
Yakhyokhuja Valikhujayev
Yakhyokhuja Valikhujayev - avatar