Recent Posts
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 오블완
- preemption #
- table not found
- 코루틴 빌더
- vfr video
- JanusWebRTCServer
- terminal
- pytest
- mp4fpsmod
- taint
- JanusWebRTC
- JanusGateway
- tolerated
- Value too long for column
- k8s #kubernetes #쿠버네티스
- 달인막창
- 헥사고날아키텍처 #육각형아키텍처 #유스케이스
- JanusWebRTCGateway
- 자원부족
- PytestPluginManager
- kotlin
- 티스토리챌린지
- 코루틴 컨텍스트
- python
- 깡돼후
- Spring Batch
- PersistenceContext
- 개성국밥
- 겨울 부산
- VARCHAR (1)
Archives
너와 나의 스토리
[BOJ] 1753 최단 경로 본문
반응형
문제: www.acmicpc.net/problem/1753
소스 코드:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#define inf 1000000000
using namespace std;
typedef pair<int, int> PI;
int vertex, edge, start;
int dist[20002];
bool visit[20002];
vector<vector<PI>> adj;
void dijkstra()
{
fill(dist, dist + vertex + 1, inf);
priority_queue<PI, vector<PI>, greater<PI>> pq;
dist[start] = 0;
pq.push({0, start});
while (!pq.empty())
{
int cur;
do
{
cur = pq.top().second;
pq.pop();
} while (!pq.empty() && visit[cur]);
if (visit[cur])
break;
visit[cur] = true;
for (PI next : adj[cur])
{
if (dist[next.first] > dist[cur] + next.second)
{
dist[next.first] = dist[cur] + next.second;
pq.push({dist[next.first], next.first});
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> vertex >> edge >> start;
adj.resize(vertex + 1);
for (int i = 0; i < edge; i++)
{
int u, v, w;
cin >> u >> v >> w;
adj[u].push_back({v, w});
}
dijkstra();
for (int i = 1; i <= vertex; i++)
{
if (dist[i] == inf) cout << "INF\n";
else
cout << dist[i] << '\n';
}
return 0;
}
반응형
'Algorithm > 다익스트라 알고리즘 (Dijkstra's Algorithm)' 카테고리의 다른 글
[BOJ] 5719 거의 최단 경로 (0) | 2019.10.02 |
---|---|
(BOJ) 15971 두 로봇 (0) | 2019.07.14 |
(BOJ) 13911 집 구하기 (0) | 2019.05.23 |
(BOJ) 14618 총깡 총깡 (1) | 2019.05.19 |
(BOJ) 10282 해킹 (0) | 2019.05.14 |
Comments