250x250
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
- openai api
- 오리스프
- 시뮬레이션
- 1654
- 그린델발트 캠핑장
- 백준 C++
- 백준
- Replit
- 알고리즘
- 프랑스 남부 섬
- iles dHyeres
- 융프라우 스위스 패스
- C++ 공부
- 군인
- 백준으로 C++ 공부
- 코딩
- auto code review
- 피르스트 자전거
- C++ 공부하기
- 대학생
- 24524
- porquerolles
- 16236 c++
- 백준으로 c++ 공부하기
- C++
- 군대코딩
- 로이커바트
- 군대
- 로이커바트 숙소
- 그린델발트 자전거
Archives
- Today
- Total
기억보다는 기록을 해볼까
[백준 14938] 서강그라운드 (C++) - 50 본문
728x90
문제
https://www.acmicpc.net/problem/14938
14938번: 서강그라운드
예은이는 요즘 가장 인기가 있는 게임 서강그라운드를 즐기고 있다. 서강그라운드는 여러 지역중 하나의 지역에 낙하산을 타고 낙하하여, 그 지역에 떨어져 있는 아이템들을 이용해 서바이벌을
www.acmicpc.net
생각
다익스트라 알고리즘을 활용해!
코드
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
const int INF = 987654321;
int n, m, r;
int item[101];
vector <pair<int, int>> map[101];
int dist[101];
bool vst[101];
int ans = -1;;
int sum, l;
void dijkstra (int start) {
for(int i = 0; i <= n; i++) dist[i] = INF;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
dist[start] = 0;
pq.push({ 0, start });
while (!pq.empty()) {
int cost = pq.top().first;
int cur = pq.top().second;
pq.pop();
if(!vst[cur]){
vst[cur] = true;
for (int i = 0; i < map[cur].size(); i++) {
int neighbor = map[cur][i].first;
int neighCost = map[cur][i].second;
int neighborDistance = cost + neighCost;
if (dist[neighbor] > neighborDistance){
dist[neighbor] = neighborDistance;
pq.push({ neighborDistance, neighbor });
}
}
}
}
}
int main() {
cin >> n >> m >> r;
for(int i = 1; i <= n; i++) cin >> item[i];
for(int i = 1; i <= r; i++) {
int a, b, l;
cin >> a >> b >> l;
map[a].push_back({b, l});
map[b].push_back({a, l});
}
for(int i = 1; i <= n; i++) {
memset(vst, false, sizeof(vst));
sum = 0;
queue<pair<int, int>> q;
dijkstra(i);
for(int j = 1; j <= n; j++){
if(dist[j] <= m) sum += item[j];
}
ans = max(ans, sum);
}
cout << ans;
}
728x90
'백준으로 C++ 공부하기' 카테고리의 다른 글
24524 아름다운 문자열 (0) | 2023.02.23 |
---|---|
[백준 17144] 미세먼지 안녕! (C++) - 51 (0) | 2022.01.18 |
[백준 11404] 플로이드 (C++) - 50 (0) | 2022.01.16 |
[백준 2638] 치즈 (C++) - 50 (0) | 2022.01.16 |
[백준 2448] 별 찍기 - 11 (C++) - 49 (0) | 2022.01.13 |
Comments