File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """
2+ n이 100,000인 것부터 복잡도 고려해야 할 것 같고
3+ 최소 등대의 개수니까 BFS?
4+ """
5+ from collections import deque
6+
7+ def solution (n , lighthouse ):
8+ graph = {}
9+ for i , j in lighthouse :
10+ if i not in graph :
11+ graph [i ] = []
12+ graph [i ].append (j )
13+
14+ if j not in graph :
15+ graph [j ] = []
16+ graph [j ].append (i )
17+ print (graph )
18+ print (graph [1 ])
19+
20+ node_counts = [(key , len (value )) for key , value in graph .items ()]
21+ node_counts .sort (key = lambda x : x [1 ], reverse = True )
22+ heap = deque (node_counts )
23+ print (heap )
24+ answer = [False ] * n
25+ print (heap .popleft ()[0 ])
26+ while all (answer ) == True :
27+ while heap :
28+ index , surround = heap .popleft ()[0 ], heap .popleft ()[1 ]
29+ answer [index ] = True
30+ answer = [True for x in answer if x in surround ]
31+
32+ # answer = 0
33+ # edge_count = [0] * (n + 1)
34+ # # print(edge_count)
35+ # for house in lighthouse:
36+ # for i in range(1, n+1):
37+ # if i in house:
38+ # edge_count[i] += 1
39+ # print(edge_count)
40+ # # print(edge_count.index(max(edge_count)))
41+ # safe = [False] * n
42+ # # print(safe)
43+ # safe[edge_count.index(max(edge_count))] = True
44+ # answer = 1
45+ # # 이제 여기서 max가 있는 index를 찾아 걔의 불을 켜주면 걔 주위는 다 상관없음
46+ # # 이런 식으로 max를 계속 키면서 모든 뱃길이 안전할 때까지 반복
47+ # while all(safe) == True:
48+
You can’t perform that action at this time.
0 commit comments