본문 바로가기
  • KEEP HUSTLE!

Python59

[백준 11657] 타임머신 - Python(파이썬) import sys def solution(): check = [float('inf')] * (N + 1) check[1] = 0 for n in range(1, N+1): for i in range(1, N+1): if check[i] == float('inf'): continue for k, l in dist[i].items(): l += check[i] if check[k] > l: if n == N: return [-1] check[k] = l return check[2:] N, M = map(int, sys.stdin.readline().split()) dist = {i: {} for i in range(1, N+1)} for _ in range(M): a, b, c = map(int, sys... 2021. 3. 11.
[백준 9370] 미확인 도착지 - Python(파이썬) from heapq import heappush, heappop import sys def solution(x): check = [100000000] * (n+1) check[x] = 0 my_heap = [(0, x)] while my_heap: k, l = heappop(my_heap) for o, p in dist[l].items(): p += k if check[o] > p: check[o] = p heappush(my_heap, (p, o)) return check T = int(sys.stdin.readline().strip()) for tc in range(T): n, m, t = map(int, sys.stdin.readline().split()) s, g, h = map(int, sys... 2021. 3. 11.
[백준 1504] 특정한 최단 경로 - Python(파이썬) from heapq import heappush, heappop import sys def solution(s): check = [float('inf')] * (N + 1) check[s] = 0 temp = [(0, s)] while temp: x, y = heappop(temp) if check[y] >= x: for n, m in dist[y]: m += x if check[n] > m: check[n] = m heappush(temp, (m, n)) return check N, E = map(int, sys.stdin.readline().split()) dist = {i: [] for i in range(N + 1)} for e in range(E): a, b, c = map(int, sys.st.. 2021. 3. 11.
[백준 1753] 최단경로 - Python(파이썬) from heapq import heappush, heappop import sys def solution(): while my_heap: my_x, my_y = heappop(my_heap) if check[my_y] >= my_x: for k, l in dist[my_y].items(): l += my_x if check[k] > l: check[k] = l heappush(my_heap, [l, k]) V, E = map(int, sys.stdin.readline().split()) start = int(sys.stdin.readline().strip()) check = [float('inf')] * (V + 1) my_heap = [] dist = [{} for _ in range(V+1)] ad.. 2021. 3. 11.
[백준 12015] 가장 긴 증가하는 부분 수열 2 - Python(파이썬) from bisect import bisect_left import sys def solution(i): x = bisect_left(result, i) if len(result) 2021. 3. 9.
[백준 1300] K번째 수 - Python(파이썬) import sys def solution(mid): temp = mid // N cnt = temp * N for i in range(temp + 1, N+1): cnt += mid // i if cnt >= k: break return cnt N = int(sys.stdin.readline().strip()) k = int(sys.stdin.readline().strip()) start, end = 1, N*N while start = k: end = middle - 1 else: start = middle + 1 print(start) 2021. 3. 9.