Loading...

[백준] 1504번. 특정한 최단 경로 (java, 다익스트라, 최단 경로)

www.acmicpc.net/problem/1504 1504번: 특정한 최단 경로 첫째 줄에 정점의 개수 N과 간선의 개수 E가 주어진다. (2 ≤ N ≤ 800, 0 ≤ E ≤ 200,000) 둘째 줄부터 E개의 줄에 걸쳐서 세 개의 정수 a, b, c가 주어지는데, a번 정점에서 b번 정점까지 양방향 길이 존 www.acmicpc.net 1-> a -> b -> n 경로와 1-> b -> a -> n 경로 중 작은 것이 답이다. 중간에 이어지는 선이 없으면 경로가 없는 것이다. import java.util.ArrayList; import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; class Edge impl..

[백준] 1238. 파티 (java, 다익스트라, 최단 경로)

www.acmicpc.net/problem/1238 1238번: 파티 첫째 줄에 N(1 ≤ N ≤ 1,000), M(1 ≤ M ≤ 10,000), X가 공백으로 구분되어 입력된다. 두 번째 줄부터 M+1번째 줄까지 i번째 도로의 시작점, 끝점, 그리고 이 도로를 지나는데 필요한 소요시간 Ti가 들어 www.acmicpc.net import java.util.ArrayList; import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; class City implements Comparable{ int node,cost; public City(int node, int cost) { super(); this.node=n..

[백준] 1753번. 최단 경로 (다익스트라, java)

import java.util.ArrayList; import java.util.PriorityQueue; import java.util.Scanner; public class Main { static int v,e,k; static ArrayList[] list; static int vis[]; public static void main(String[] args) { Scanner sc=new Scanner(System.in); v=sc.nextInt(); e=sc.nextInt(); k=sc.nextInt();//시작점 vis=new int[v+1]; list=new ArrayList[v+1]; for (int i = 1; i

백준 10282번 해킹(파이썬)

www.acmicpc.net/problem/10282 10282번: 해킹 최흉최악의 해커 yum3이 네트워크 시설의 한 컴퓨터를 해킹했다! 이제 서로에 의존하는 컴퓨터들은 점차 하나둘 전염되기 시작한다. 어떤 컴퓨터 a가 다른 컴퓨터 b에 의존한다면, b가 감염되면 �� www.acmicpc.net 다익스트라 유형 import sys import collections import heapq t=int(sys.stdin.readline()) for kk in range(t): n,d,c=map(int,sys.stdin.readline().split()) graph=collections.defaultdict(list) for i in range(d): a,b,s=map(int,sys.stdin.readlin..

백준 1753번 다익스트라 (파이썬)

import sys import collections import heapq V,E=map(int,sys.stdin.readline().split()) K=int(sys.stdin.readline()) graph=collections.defaultdict(list) for i in range(E): u,v,w=map(int,sys.stdin.readline().split()) graph[u].append((v,w)) dist=collections.defaultdict(int) q=[(0,K)] while q: time,node=heapq.heappop(q) if node not in dist: dist[node]=time for v,w in graph[node]: alt=time+w heapq.heapp..