9370번

· 백준
코드#include #include #include #include #include using namespace std;const int INF = 987654321;int T, n, m, t, s, g, h, a, b, d, x;vector> adj[2003];vector wh, res;int distS[2003], distG[2003], distH[2003]; // s, g, h에서 각각의 최단 거리void INPUT() { cin >> n >> m >> t; cin >> s >> g >> h; for (int i = 0; i > a >> b >> d; adj[a].push_back({b, d}); adj[b].push_back({a, d}); } ..
· 백준
코드 import heapq, sys input = sys.stdin.readline INF = 987654321 # 다익스트라 알고리즘 def dijkstra(x,graph): visited = [INF]*(n+1) queue = [(0,x)] visited[x] = 0 while queue: cost, now = heapq.heappop(queue) if cost > visited[now]: continue for i in graph[now]: newcost = cost + i[1] if visited[i[0]] > newcost: visited[i[0]] = newcost heapq.heappush(queue, (newcost, i[0])) return visited tc = int(input())..