diff --git "a/YoonYn9915/dijkstra/2025-06-23-[\353\260\261\354\244\200]-#1504-\355\212\271\354\240\225\355\225\234 \354\265\234\353\213\250 \352\262\275\353\241\234.py" "b/YoonYn9915/dijkstra/2025-06-23-[\353\260\261\354\244\200]-#1504-\355\212\271\354\240\225\355\225\234 \354\265\234\353\213\250 \352\262\275\353\241\234.py" new file mode 100644 index 0000000..a84f810 --- /dev/null +++ "b/YoonYn9915/dijkstra/2025-06-23-[\353\260\261\354\244\200]-#1504-\355\212\271\354\240\225\355\225\234 \354\265\234\353\213\250 \352\262\275\353\241\234.py" @@ -0,0 +1,35 @@ +import sys +import heapq + +input = sys.stdin.readline +INF = float('inf') + +N, E = map(int, input().split()) +graph = [[] for _ in range(N + 1)] +for _ in range(E): + a, b, c = map(int, input().split()) + graph[a].append((b, c)) + graph[b].append((a, c)) +v1, v2 = map(int, input().split()) + + + +def dijkstra(start, end): + dist = [INF] * (N + 1) + dist[start] = 0 + hq = [(0, start)] + while hq: + len, node = heapq.heappop(hq) + if len > dist[node]: + continue + for next_node, val in graph[node]: + if dist[next_node] > dist[node] + val: + dist[next_node] = dist[node] + val + heapq.heappush(hq, (dist[next_node], next_node)) + return dist[end] + + +path1 = dijkstra(1, v1) + dijkstra(v1, v2) + dijkstra(v2, N) +path2 = dijkstra(1, v2) + dijkstra(v2, v1) + dijkstra(v1, N) + +print(-1) if path1 >= INF and path2 >= INF else print(min(path1, path2)) diff --git "a/YoonYn9915/dijkstra/2025-06-28-[\353\260\261\354\244\200]-#1753-\354\265\234\353\213\250 \352\262\275\353\241\234.py" "b/YoonYn9915/dijkstra/2025-06-28-[\353\260\261\354\244\200]-#1753-\354\265\234\353\213\250 \352\262\275\353\241\234.py" new file mode 100644 index 0000000..34bcea3 --- /dev/null +++ "b/YoonYn9915/dijkstra/2025-06-28-[\353\260\261\354\244\200]-#1753-\354\265\234\353\213\250 \352\262\275\353\241\234.py" @@ -0,0 +1,41 @@ +import heapq +import sys + +input = sys.stdin.readline + +V, E = map(int, input().split()) +start = int(input()) +graph = [[] for _ in range(V + 1)] + +for _ in range(E): + u, v, w = map(int, input().split()) + + graph[u].append((v, w)) + + +def dijkstra(start): + distances = [float("inf")] * (V + 1) + distances[start] = 0 + q = [] + heapq.heappush(q, (distances[start], start)) + + while q: + cnt_distance, node = heapq.heappop(q) + + if distances[node] < cnt_distance: + continue + + for adjacency_node, distance in graph[node]: + cal_distance = distances[node] + distance + + if cal_distance < distances[adjacency_node]: + distances[adjacency_node] = cal_distance + heapq.heappush(q, (cal_distance, adjacency_node)) + + return distances + + +result = dijkstra(start) + +for i in range(1, len(result)): + print("INF" if result[i] == float("inf") else result[i]) \ No newline at end of file diff --git "a/YoonYn9915/implementation/2025-06-28-[\353\260\261\354\244\200]-#15905-\354\212\244\355\205\224\353\235\274\352\260\200 \354\271\230\355\202\250\354\235\204 \354\204\240\353\254\274\355\226\210\354\226\264\354\232\224.py" "b/YoonYn9915/implementation/2025-06-28-[\353\260\261\354\244\200]-#15905-\354\212\244\355\205\224\353\235\274\352\260\200 \354\271\230\355\202\250\354\235\204 \354\204\240\353\254\274\355\226\210\354\226\264\354\232\224.py" new file mode 100644 index 0000000..efeee6a --- /dev/null +++ "b/YoonYn9915/implementation/2025-06-28-[\353\260\261\354\244\200]-#15905-\354\212\244\355\205\224\353\235\274\352\260\200 \354\271\230\355\202\250\354\235\204 \354\204\240\353\254\274\355\226\210\354\226\264\354\232\224.py" @@ -0,0 +1,18 @@ +N = int(input()) + +arr = [] + +for _ in range(N): + q, p = list(map(int, input().split())) + arr.append([q, p]) + +arr.sort(reverse=True) + +count = 0 +for i in range(5, len(arr)): + if arr[4][0] == arr[i][0]: + count += 1 + else: + break + +print(count) \ No newline at end of file