Paste Search Dynamic
Solution celebrity
1. #User function Template for python3
2.
3. class Solution:
4.
5.     #Function to find if there is a celebrity in the party or not.
6.     def celebrity(self, M, n):
7.         # code here
8.         indegree = [0]*n
9.         outdegree = [0]*n
10.
11.         for i in range(n):
12.             for j in range(n):
13.                 if M[i][j]!=0:
14.                     outdegree[i] += 1
15.                     indegree[j] += 1
16.         for i in range(n):
17.             if indegree[i] == n-1 and outdegree[i] ==0:
18.                 return 1
19.         return -1
20.
21. #{
22. #  Driver Code Starts
23. #Initial Template for Python 3
24.
25. if __name__ == '__main__':
26.     t = int(input())
27.     for _ in range(t) :
28.         n = int(input())
29.         a = list(map(int,input().strip().split()))
30.         k = 0
31.         m = []
32.         for i in range(n):
33.             row = []
34.             for j in range(n):
35.                 row.append(a[k])
36.                 k+=1
37.             m.append(row)
38.         ob = Solution()
39.         print(ob.celebrity(m,n))
40. # } Driver Code Ends
Parsed in 0.015 seconds