-
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
[최단 경로] 2176063 김서현 #353
Open
sforseohn
wants to merge
22
commits into
Altu-Bitu-Official:2176063-김서현2
Choose a base branch
from
sforseohn:13-assignment
base: 2176063-김서현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
[최단 경로] 2176063 김서현 #353
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5c5694a
[5월 19일] 트리 라이브 코딩 코드 업로드
jk0527 cf31227
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 a8cc122
[5월 19일] 트리 리드미 수정
jk0527 5ab3590
[5월 23일] 트리 과제 코드 업로드
jk0527 20be664
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 dad8d2c
[5월 23일] 트리 리드미 수정
jk0527 1373cde
[5월 23일] 최단 경로 강의 자료 업로드
jk0527 6d1de48
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 b57dc56
[5월 23일] 최단 경로 리드미 업로드
jk0527 c908c33
[5월 23일] 리드미 수정
jk0527 dfb69e0
[5월 26일] 최단 경로 강의 자료 수정
jk0527 65bd5df
[5월 26일] 최단 경로 강의 자료 수정
jk0527 7b46298
[5월 26일] 최단 경로 라이브 코딩 코드 업로드
jk0527 74a7044
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 fce223d
[5월 26일] 최단 경로 리드미 수정
jk0527 91e590f
[최단 경로] 0530
sforseohn c36add7
Merge branch '2176063-김서현2' into 13-assignment
sforseohn 0efc874
[최단 경로] 0530
sforseohn 020306f
Merge branch '13-assignment' of https://github.com/sforseohn/Altu-Bit…
sforseohn 042e028
[최단 경로] 0602
sforseohn 5cedeff
[최단 경로] 추가제출
sforseohn 0e0ea97
Merge branch '2176063-김서현2' into 13-assignment
sforseohn 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,71 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <queue> | ||
|
||
using namespace std; | ||
|
||
typedef pair<int, int> ci; | ||
const int INF = 1e5; // n * 가중치의 최대값 | ||
|
||
int dijkstra(int start, int end, int n, vector<vector<ci>> &graph) { | ||
vector<int> dist(n+1, INF); | ||
dist[start] = 0; // 시작점에서의 시간 | ||
priority_queue<ci, vector<ci>, greater<>> pq; | ||
pq.push({0, start}); // 시간, 시작점 | ||
|
||
while(!pq.empty()) { | ||
int time = pq.top().first; // 지금 뽑힌 정점의 time | ||
int node = pq.top().second; | ||
pq.pop(); // 안하면 시간초과 | ||
|
||
if(time > dist[node]) { // 이미 저장된 시간보다 길다 -> 업데이트할 필요 X | ||
continue; | ||
} | ||
|
||
for(int i = 0; i < graph[node].size(); i++) { | ||
int next_node = graph[node][i].first; | ||
int next_time = graph[node][i].second + time; | ||
|
||
if(dist[next_node] > next_time) { | ||
dist[next_node] = next_time; | ||
pq.push({next_time, next_node}); | ||
} | ||
} | ||
} | ||
return dist[end]; | ||
} | ||
|
||
int findLongest(int x, int n, vector<vector<ci>> graph) { | ||
int ans = 0; | ||
|
||
for(int i = 1; i <= n; i++) { | ||
int time = dijkstra(i, x, n, graph) + dijkstra(x, i, n, graph); // 가는 시간 + 오는 시간 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dijkstra를 한 번만 실행하니까 시간이 두 배로 줄었어요..!! 감사합니다! |
||
ans = max(ans, time); // 최대값 구하기 | ||
} | ||
return ans; | ||
} | ||
|
||
int main() { | ||
ios_base::sync_with_stdio(0); | ||
cin.tie(0); | ||
cout.tie(0); | ||
|
||
int n, m, x, a, b, t; | ||
|
||
// 입력 | ||
cin >> n >> m >> x; // x: 파티 목적지 | ||
vector<vector<ci>> graph(n+1, vector<ci>(0)); | ||
|
||
while(m--) { | ||
cin >> a >> b >> t; | ||
graph[a].push_back({b, t}); // 단방향 도로 | ||
} | ||
|
||
// 연산 | ||
int ans = findLongest(x, n, graph); | ||
|
||
// 출력 | ||
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.
P3. time은 다른 언어에서 키워드인 것 같아요. 혹시 모르니까 조심하세요~⚠️