-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[최단경로] 2171024 신수정 #362
Open
chock-cho
wants to merge
32
commits into
Altu-Bitu-Official:2171024-신수정2
Choose a base branch
from
chock-cho:13_assignment
base: 2171024-신수정2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[최단경로] 2171024 신수정 #362
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
de9881a
[4월 12일] 동적 계획법 강의 자료 업로드
jk0527 8ef72d6
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 6223f7e
[4월 12일] 동적 계획법 리드미 업로드
jk0527 da38b52
[4월 14일] 동적 계획법 강의 자료 수정
jk0527 53b5bfa
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 3a83c8a
[4월 14일] 리드미 수정
jk0527 149f4c0
[4월 14일] 동적 계획법 라이브코딩 코드 업로드
jk0527 1d0e018
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 1bcacb0
[4월 14일] 동적 계획법 리드미 수정
jk0527 cbdb583
[5월 2일] 동적 계획법 강의자료 수정
jk0527 c2091d7
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 1b3b114
[5월 2일] 백트래킹 과제 코드 업로드
jk0527 86da014
[5월 2일] 동적 계획법 과제 코드 업로드
jk0527 bd2b014
[5월 2일] 백트래킹 리드미 수정
jk0527 d51f618
[5월 2일] 동적 계획법 리드미 수정
jk0527 93c419c
[5월 5일] 이분 탐색 리드미 업로드
jk0527 88830b6
[5월 5일] 이분 탐색 강의 자료 업로드
jk0527 5a6372c
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 ad6eebb
[5월 5일] 이분 탐색 라이브 코딩 코드 업로드
jk0527 9f9b791
[5월 5일] 이분 탐색 리드미 수정
jk0527 3a55ea1
[5월 5일] 리드미 수정
jk0527 cedeb06
[5월 9일] 이분 탐색 과제 코드 업로드
jk0527 7699152
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 bbfbc93
[5월 9일] 투 포인터 리드미 업로드
jk0527 7baa1de
[5월 10일] 이분 탐색 리드미 수정
jk0527 b6f7843
[5월 10일] 투 포인터 강의 자료 업로드
jk0527 b92e936
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 56d70ae
[5월 10일] 리드미 수정
jk0527 3549143
[0523] 트리 -필수문제
chock-cho 0a250a4
[0523] 트리-필수문
chock-cho de869b8
[0530] 최단경로
chock-cho fe3f732
[0530] 최단경로
chock-cho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// 1238 파티 | ||
// 다익스트라 알고리즘 | ||
/* | ||
문제 해석: | ||
(1번 학생 집-> 파티장소)+(파티장소->1번 학생 집) vs ... vs(i번째 학생 집->파티장소)+(파티장소->i번째 학생 집) 거리 중 최댓값을 구하는 것 | ||
파티장소를 출발점으로 다익스트라 돌리고(step1), 뒤집은 그래프로도 출발점을 돌리면 (step2)--> step1+step2=complete | ||
*/ | ||
#include <iostream> | ||
#include <vector> | ||
#include <queue> | ||
|
||
using namespace std; | ||
typedef pair<int, int> pi; | ||
const int INF = 1e5; | ||
|
||
vector<int> dijkstra(int start, int N, vector<vector<pi>> &adj) { | ||
vector<int> dist(N + 1, INF); //dist 배열을 INF로 초기화 | ||
priority_queue<pi, vector<pi>, greater<pi>> pq; // pq 선언 | ||
|
||
dist[start] = 0; | ||
pq.push({0, start}); | ||
|
||
while (!pq.empty()) { | ||
int cur_cost = pq.top().first; // 현재까지의 cost값 | ||
int cur = pq.top().second; // cur := 현재 정점 | ||
pq.pop(); | ||
|
||
if (cur_cost > dist[cur]) { //이미 더 작은 값으로 기록된 정점이 있다면 | ||
continue; | ||
} | ||
for (int i = 0; i < adj[cur].size(); i++) { // 현재 값과 연결된 모든 정점들을 탐색해본다. | ||
int nxt = adj[cur][i].first; | ||
int nxt_cost = cur_cost + adj[cur][i].second; | ||
if (nxt_cost < dist[nxt]) { | ||
dist[nxt] = nxt_cost; | ||
pq.push({nxt_cost, nxt}); | ||
} | ||
} | ||
} | ||
return dist; | ||
} | ||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL), cout.tie(NULL); | ||
|
||
int N, M, X, a, b, c; | ||
cin >> N >> M >> X; | ||
vector<vector<pi>> adj(N + 1, vector<pi>(0)); | ||
while(M--){ | ||
cin >> a >> b >> c; | ||
adj[a].push_back({b,c}); | ||
} | ||
|
||
vector<int> vr1 = dijkstra(X, N, adj); | ||
|
||
int ans = 0; | ||
for (int i = 1; i <= N; i++) { | ||
vector<int> vr2 = dijkstra(i, N, adj); // i 부터 X의의 최단 시간 | ||
ans = max(ans, vr1[i] + vr2[X]); | ||
} | ||
|
||
cout << ans << "\n"; | ||
|
||
return 0; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아~~~깔끔합니다~~ 👍 👍