Skip to content

Commit

Permalink
Merge pull request #185 from AlgoLeadMe/54-tgyuuAn
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn authored May 18, 2024
2 parents 11ccafc + e189ed4 commit 45ac9fd
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@
| 41์ฐจ์‹œ | 2024.03.04 | DP | <a href="https://www.acmicpc.net/problem/2240">์ž๋‘๋‚˜๋ฌด</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/148
| 42์ฐจ์‹œ | 2024.03.07 | DFS | <a href="https://www.acmicpc.net/problem/2239">์Šค๋„์ฟ </a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/152
| 43์ฐจ์‹œ | 2024.03.10 | ์ด๋ถ„ ํƒ์ƒ‰ | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/64062">์ง•๊ฒ€๋‹ค๋ฆฌ ๊ฑด๋„ˆ๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/157
| 44์ฐจ์‹œ | 2023.03.13 | ํŠธ๋ผ์ด | <a href="https://www.acmicpc.net/problem/14725">๊ฐœ๋ฏธ๊ตด</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/159
| 45์ฐจ์‹œ | 2023.03.16 | ํŠธ๋ผ์ด | <a href="https://www.acmicpc.net/problem/31413">ํŠธ๋ผ์ด</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/162
| 46์ฐจ์‹œ | 2023.03.20 | ํŠธ๋ผ์ด | <a href="https://www.acmicpc.net/problem/27652">AB</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/165
| 47์ฐจ์‹œ | 2023.03.22 | ์ˆ˜ํ•™, ๋ถ„ํ• ์ •๋ณต | <a href="https://www.acmicpc.net/problem/15824">๋„ˆ ๋ด„์—๋Š” ์บก์‚ฌ์ด์‹ ์ด ๋ง›์žˆ๋‹จ๋‹ค</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/167
| 48์ฐจ์‹œ | 2023.03.25 | ๋ฒจ๋งŒ ํฌ๋“œ | <a href="https://www.acmicpc.net/problem/1738">๊ณจ๋ชฉ๊ธธ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/171
| 49์ฐจ์‹œ | 2023.03.29 | DP | <a href="https://www.acmicpc.net/problem/10217">KCM Travel</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/174
| 44์ฐจ์‹œ | 2024.03.13 | ํŠธ๋ผ์ด | <a href="https://www.acmicpc.net/problem/14725">๊ฐœ๋ฏธ๊ตด</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/159
| 45์ฐจ์‹œ | 2024.03.16 | ํŠธ๋ผ์ด | <a href="https://www.acmicpc.net/problem/31413">ํŠธ๋ผ์ด</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/162
| 46์ฐจ์‹œ | 2024.03.20 | ํŠธ๋ผ์ด | <a href="https://www.acmicpc.net/problem/27652">AB</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/165
| 47์ฐจ์‹œ | 2024.03.22 | ์ˆ˜ํ•™, ๋ถ„ํ• ์ •๋ณต | <a href="https://www.acmicpc.net/problem/15824">๋„ˆ ๋ด„์—๋Š” ์บก์‚ฌ์ด์‹ ์ด ๋ง›์žˆ๋‹จ๋‹ค</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/167
| 48์ฐจ์‹œ | 2024.03.25 | ๋ฒจ๋งŒ ํฌ๋“œ | <a href="https://www.acmicpc.net/problem/1738">๊ณจ๋ชฉ๊ธธ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/171
| 49์ฐจ์‹œ | 2024.03.29 | DP | <a href="https://www.acmicpc.net/problem/10217">KCM Travel</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/174
| 50์ฐจ์‹œ | 2024.04.01 | BFS | <a href="https://www.acmicpc.net/problem/9328">์—ด์‡ </a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/175
| 51์ฐจ์‹œ | 2023.04.07 | BFS | <a href="https://www.acmicpc.net/problem/5213">๊ณผ์™ธ๋งจ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/179
| 52์ฐจ์‹œ | 2023.05.06 | ์œ„์ƒ์ •๋ ฌ | <a href="https://www.acmicpc.net/problem/1516">๊ฒŒ์ž„ ๊ฐœ๋ฐœ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/182
| 53์ฐจ์‹œ | 2023.05.09 | ๋ฐฑํŠธ๋ž˜ํ‚น | <a href="https://www.acmicpc.net/problem/12100">2048 (Easy)</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/184
| 51์ฐจ์‹œ | 2024.04.07 | BFS | <a href="https://www.acmicpc.net/problem/5213">๊ณผ์™ธ๋งจ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/179
| 52์ฐจ์‹œ | 2024.05.06 | ์œ„์ƒ์ •๋ ฌ | <a href="https://www.acmicpc.net/problem/1516">๊ฒŒ์ž„ ๊ฐœ๋ฐœ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/182
| 53์ฐจ์‹œ | 2024.05.09 | ๋ฐฑํŠธ๋ž˜ํ‚น | <a href="https://www.acmicpc.net/problem/12100">2048 (Easy)</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/184
| 54์ฐจ์‹œ | 2024.05.14 | ๋‹ค์ต์ŠคํŠธ๋ผ | <a href="https://www.acmicpc.net/problem/9370">๋ฏธํ™•์ธ ๋„์ฐฉ์ง€</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/185
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from collections import defaultdict
from heapq import *
import sys

INF = 50_000_001

def input(): return sys.stdin.readline().rstrip()

T = int(input())

for _ in range(T):
cnt_node, cnt_edge, cnt_dedication = map(int, input().split())
start_node, g, h = map(int, input().split())

graph = defaultdict(lambda : defaultdict(int))
for _ in range(cnt_edge):
start, destination, cost = map(int,input().split())
graph[start][destination] = cost
graph[destination][start] = cost

node_dedications = set()
for _ in range(cnt_dedication):
node_dedications.add(int(input()))

table = [INF for _ in range(cnt_node+1)]
table[start_node] = 0

visited = set()
heap = []
heappush(heap, [0, start_node, 1])
flag = [1 for _ in range(cnt_node+1)]

while heap:
now_cost, now_node, now_flag = heappop(heap)

if now_node in visited: continue
visited.add(now_node)

if flag[now_node] == 1 and now_flag == 0: flag[now_node] = 0

for next_node in graph[now_node]:
cost = graph[now_node][next_node]

if (now_cost + cost) > table[next_node]: continue

table[next_node] = now_cost + cost

new_flag = now_flag
# ๋งŒ์•ฝ, ์ง€๊ธˆ ์›€์ง์ด๋ ค๋Š” ๋„๋กœ๊ฐ€ ๋ƒ„์ƒˆ๊ฐ€ ๋‚˜๋Š” ๋„๋กœ์˜€์„ ๊ฒฝ์šฐ flag๋ฅผ 0๋กœ ๋ฐ”๊ฟˆ
if (now_node, next_node) in {(g, h), (h, g)}: new_flag = 0

heappush(heap, [now_cost + cost, next_node, new_flag])

answer = []
for dedication in node_dedications:
if flag[dedication] == 0: answer.append(dedication)

print(*sorted(answer))

0 comments on commit 45ac9fd

Please sign in to comment.