-
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
base: 2176063-김서현2
Are you sure you want to change the base?
[최단 경로] 2176063 김서현 #353
Conversation
코드리뷰완료 |
#include <vector> | ||
|
||
using namespace std; | ||
const int CONNECTED = 1; |
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.
오! 이렇게 하니까 가독성이 더 좋은 것 같아요!! 배워갑니다~ 🦸
if(graph[i][k] && graph[k][j]) { // i가 k보다 작고, k가 j보다 작다 -> i가 j보다 작다 | ||
graph[i][j] = CONNECTED; // 연결 표시 |
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.
👍
13_최단 경로/필수/2458.cpp
Outdated
for(int i = 1; i <= n; i++) { | ||
int cnt = 0; | ||
for(int j = 1; j <= n; j++) { | ||
if(graph[i][j] || graph[j][i]) { // 작거나 크다는 걸 알면 |
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. 이 반대의 경우에 break;
를 하는 것도 좋은 방법일 것 같아요~ cnt는 for문의 끝에 도달했을 때 하나 올려주면 되고요~
13_최단 경로/필수/2458.cpp
Outdated
if(graph[i][j] || graph[j][i]) { // 작거나 크다는 걸 알면 | ||
cnt++; // 카운트 증가 | ||
|
||
if(cnt >= n - 1) { // n-1명의 학생들에 연결되어있으면 |
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.
if(cnt == n-1)
이어도 될 것 같아요~
int main() { | ||
ios_base::sync_with_stdio(0); | ||
cin.tie(0); | ||
cout.tie(0); | ||
|
||
int n, m, a, b; | ||
|
||
// 입력 | ||
cin >> n >> m; | ||
vector<vector<int>> graph(n+1, vector<int>(n+1, 0)); | ||
|
||
while(m--) { | ||
cin >> a >> b; | ||
graph[a][b] = CONNECTED; // 연결 표시 | ||
} | ||
|
||
// 연산 | ||
floydWarshall(n, graph); // 플로이드 워셜 | ||
int ans = findStudent(n, graph); // 키가 몇 번째인지 알 수 있는 학생 수 | ||
|
||
// 출력 | ||
cout << ans << '\n'; | ||
|
||
return 0; | ||
} |
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.
main함수 너무 깔끔합니다! 💯 🥇
pq.push({0, start}); // 시간, 시작점 | ||
|
||
while(!pq.empty()) { | ||
int time = pq.top().first; // 지금 뽑힌 정점의 time |
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은 다른 언어에서 키워드인 것 같아요. 혹시 모르니까 조심하세요~
13_최단 경로/필수/1238.cpp
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
P3. dijkstra(x,i,n,graph)
는 한 번만 실행되도 되기 때문에 for문 전에 실행한 결과를 저장해 두고 사용하면 시간을 더 줄일 수 있을 거에요.
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.
dijkstra를 한 번만 실행하니까 시간이 두 배로 줄었어요..!! 감사합니다!
리뷰 해주신대로 수정하여 제출했습니다! 마지막까지 감사합니다 ❤ |
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.
[최단 경로 구현 문제 추가 제출 확인 완료]
추가 제출 확인했습니다!🥰🥰
수고하셨습니다!
인적사항
학번: 2176063
이름: 김서현
과제 제출
기존 제출 : 1238, 2458
추가 제출 : 15681