Notice
Recent Posts
Recent Comments
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 | 29 | 30 |
| 31 |
Tags
- 2075번
- 백준 24444 c++
- Unreal
- WinAPI
- lis응용
- unrealengine
- 다익스트라
- 2d 박스충돌
- 11286번
- DirectX12
- directx12 그리기 연산2
- 그리기 연산
- dx12 정리
- 드래곤플라이트 모작
- 루트서명
- 4134번
- 랜더링 파이프라인
- 백준 c++ 24479번
- Perforce
- dx12
- 다음소수
- 바이토닉 수열
- 2565번
- 애니메이션
- 백준 1260 c++
- 백준
- C++
- 24779
- 뱀과사다리게임
- BFS
Archives
- Today
- Total
game-1 님의 블로그
[백준]1916 번 C++ 최소 비용 구하기 컴파일에러 본문


풀이)
이 문제는 전형적인 다익스트라 알고리즘을 사용하면 해결되는 문제이지만 주의할 점은,,
main문에 return 0;를 생략하면 컴파일 에러가 뜹니다
최신 컴파일러들은 이를 알아서 해결해주기때문에 컴퓨터에서는 별 문제가 없고, 백준 대부분의 문제의 경우 생략해도 오류가 생기지 않으나, 해당 문제의 경우 컴파일 에러가 뜨네요
저처럼 에러가 뜨는 경우 return 0;를 추가해 보시면 좋을 것 같습니다. 다음은 코드입니다.
코드)
#include<iostream>
#include<vector>
#include<queue>
#include<limits>
using namespace std;
const int INF = numeric_limits<int>::max();
vector<vector<pair<int, int>>> graph;
vector<int> dist;
int dijkstra(int start, int end) {
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
pq.push({0, start});
dist[start] = 0;
while (not pq.empty()) {
int current = pq.top().second;
int distance = pq.top().first;
pq.pop();
if (dist[current] < distance) continue;
for (const auto& a : graph[current]) {
int nextnode = a.second;
int nextdist = distance + a.first;
if (dist[nextnode] > nextdist) {
dist[nextnode] = nextdist;
pq.push({nextdist, nextnode});
}
}
}
return dist[end];
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int n, m;
cin >> n >> m;
graph.resize(n + 1);
dist.assign(n + 1, INF);
while (m--) {
int u, v, value;
cin >> u >> v >> value;
graph[u].push_back({value, v});
}
int start, end;
cin >> start >> end;
cout << dijkstra(start, end);
return 0;
}
'백준 문제풀이' 카테고리의 다른 글
| [백준] 2252번 C++ 줄 세우기 , 위상 정렬 (0) | 2025.02.15 |
|---|---|
| [백준] 1238번 C++ 파티 (1) | 2025.02.07 |
| [백준] c++ 13549번 숨바꼭질 3 (bfs풀이) (1) | 2025.02.06 |
| [백준] 1504번 C++ 특정한 최단 경로 (0) | 2025.02.05 |
| [백준] 2075번 N번째 큰 수 C++ (2) | 2025.02.03 |