From 0946f13da512e610ba1b436b96538f1788c610be Mon Sep 17 00:00:00 2001 From: wnsmir <163817041+wnsmir@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:56:57 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Create=20=EC=A0=84=EB=B3=B4.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\240\204\353\263\264.py" | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 "wnsmir/\354\265\234\353\213\250\352\262\275\353\241\234/\354\240\204\353\263\264.py" diff --git "a/wnsmir/\354\265\234\353\213\250\352\262\275\353\241\234/\354\240\204\353\263\264.py" "b/wnsmir/\354\265\234\353\213\250\352\262\275\353\241\234/\354\240\204\353\263\264.py" new file mode 100644 index 0000000..a8f35fd --- /dev/null +++ "b/wnsmir/\354\265\234\353\213\250\352\262\275\353\241\234/\354\240\204\353\263\264.py" @@ -0,0 +1,5 @@ +import heapq +import sys + +input = sys.stdin.readline +N, M ,C = map(int, input().split()) From f94cd26a9cceb2e31a6c55d1dd88cab4bf44fca3 Mon Sep 17 00:00:00 2001 From: wnsmir <163817041+wnsmir@users.noreply.github.com> Date: Fri, 10 Jan 2025 17:08:10 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Update=20=EC=A0=84=EB=B3=B4.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\240\204\353\263\264.py" | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git "a/wnsmir/\354\265\234\353\213\250\352\262\275\353\241\234/\354\240\204\353\263\264.py" "b/wnsmir/\354\265\234\353\213\250\352\262\275\353\241\234/\354\240\204\353\263\264.py" index a8f35fd..766b65c 100644 --- "a/wnsmir/\354\265\234\353\213\250\352\262\275\353\241\234/\354\240\204\353\263\264.py" +++ "b/wnsmir/\354\265\234\353\213\250\352\262\275\353\241\234/\354\240\204\353\263\264.py" @@ -2,4 +2,38 @@ import sys input = sys.stdin.readline -N, M ,C = map(int, input().split()) +INF = 987654321 + +N, M ,start = map(int, input().split()) +graph = [[]for i in range(N+1)] +distance = [INF]*(N+1) + +for _ in range(M+1): + X, Y, Z = map(int, input().split()) + graph[X].append(Y, Z) + +def dijkstra(start): + q = [] + heapq.heappush(q, (0,start)) + distance[start] = 0 + while q: + dist, now = heapq.heappop(q) + if distance[now] < dist: + continue + for i in graph[now]: + cost = dist + i[1] + if cost < distance[i[0]]: + distance[i[0]] = cost + heapq.heappush(q, (cost,i[0])) + +dijkstra(start) + +count = 0 +max_distance = 0 + +for d in distance: + if d != INF: + count += 1 + max_distance = max(max_distance, d) + +print(count -1, max_distance) \ No newline at end of file