Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Code Study
- Paper list
- Object Detection
- Pytorch pruning
- 프로그래머스네트워크
- 코딩테스트연습
- SSD 리뷰
- ssd
- 프로그래머스
- Pruning Tutorial
- 코딩테스트네트워크
- deep learning
- 타겟넘버bfs
- 코딩테스트2단계
- Single Shot MultiBox Detector
- 커피후기
- 프로그래머스bfs
- 프로그래머스타겟넘버파이썬
- Faster R-CNN
- 다음큰숫자
- Two stage Detector
- 프로그래머스타겟넘버
- 프로그래머스파이썬
- ECCV
- 프로그래머스게임맵최단거리
- 프로그래머스너비우선탐색
- pytorch
- 최솟값 만들기
- One stage detector
- 프로그래머스타겟넘버정답
Archives
- Today
- Total
soyeonland
프로그래머스 dfs bfs 여행경로 본문
문제
잘못한 풀이
더보기
from collections import deque
#1. 같은 항공권이 중복될 수 있음
#2. 모든 도시를 방문할 수 없는 알고리즘?
def solution(tickets):
answer = []
graph = []
visited = []
all_dict = {}
all_dict_revers = {}
#print("a"<"b")
def make_graph():
nonlocal graph, all_dict, visited, all_dict_revers
all = []
for start, end in tickets:
all.append(start)
all.append(end)
all = set(all)
all = list(all)
all = sorted(all)
for idx, city in enumerate(all):
all_dict[city] = idx
for city, idx in all_dict.items():
all_dict_revers[idx] = city
all_len = len(all)
graph = [[0]*(all_len) for _ in range(all_len)]
visited = [[0]*(all_len) for _ in range(all_len)]
for start, end in tickets:
start_num = all_dict[start]
end_num = all_dict[end]
graph[start_num][end_num] = 1
def bfs():
nonlocal answer
q = deque()
q.append("ICN")
while(len(q)>=1):
cur_city = q.popleft()
cur_num = all_dict[cur_city]
answer.append(cur_city)
for next_num in range(len(graph[cur_num])):
if graph[cur_num][next_num]==0:
continue
if visited[cur_num][next_num]==1:
continue
next_city = all_dict_revers[next_num]
visited[cur_num][next_num] = 1
q.append(next_city)
break
make_graph()
bfs()
# for start, end in tickets:
#print('graph',graph, 'all_dict',all_dict, "all_dict reverse", all_dict_revers)
return answer
'Study > 코딩테스트 연습' 카테고리의 다른 글
프로그래머스 dfs/bfs 게임 맵 최단거리 파이썬 (1) | 2024.10.13 |
---|---|
프로그래머스 dfs/bfs 네트워크 파이썬 (0) | 2024.10.13 |
프로그래머스 dfs/bfs 타겟넘버 python (0) | 2024.10.09 |
단어변환 (0) | 2024.10.02 |
귤고르기 (0) | 2024.07.30 |