Skip to content
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
wants to merge 22 commits into
base: 2176063-김서현2
Choose a base branch
from

Conversation

sforseohn
Copy link

@sforseohn sforseohn commented May 30, 2023

인적사항

학번: 2176063
이름: 김서현


과제 제출

기존 제출 : 1238, 2458
추가 제출 : 15681


@sforseohn sforseohn changed the base branch from main to 2176063-김서현2 May 30, 2023 08:33
@sforseohn sforseohn changed the base branch from 2176063-김서현2 to 2176063-김서현 May 30, 2023 08:34
@sforseohn sforseohn changed the base branch from 2176063-김서현 to 2176063-김서현2 May 30, 2023 08:34
@Dong-droid
Copy link
Contributor

코드리뷰완료
수고하셨습니다 😸

#include <vector>

using namespace std;
const int CONNECTED = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오! 이렇게 하니까 가독성이 더 좋은 것 같아요!! 배워갑니다~ 🦸

Comment on lines +11 to +12
if(graph[i][k] && graph[k][j]) { // i가 k보다 작고, k가 j보다 작다 -> i가 j보다 작다
graph[i][j] = CONNECTED; // 연결 표시
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

for(int i = 1; i <= n; i++) {
int cnt = 0;
for(int j = 1; j <= n; j++) {
if(graph[i][j] || graph[j][i]) { // 작거나 크다는 걸 알면
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3. 이 반대의 경우에 break;를 하는 것도 좋은 방법일 것 같아요~ cnt는 for문의 끝에 도달했을 때 하나 올려주면 되고요~

if(graph[i][j] || graph[j][i]) { // 작거나 크다는 걸 알면
cnt++; // 카운트 증가

if(cnt >= n - 1) { // n-1명의 학생들에 연결되어있으면
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(cnt == n-1)이어도 될 것 같아요~

Comment on lines +36 to +60
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;
}
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3. time은 다른 언어에서 키워드인 것 같아요. 혹시 모르니까 조심하세요~ ⚠️

int ans = 0;

for(int i = 1; i <= n; i++) {
int time = dijkstra(i, x, n, graph) + dijkstra(x, i, n, graph); // 가는 시간 + 오는 시간
Copy link
Contributor

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문 전에 실행한 결과를 저장해 두고 사용하면 시간을 더 줄일 수 있을 거에요.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dijkstra를 한 번만 실행하니까 시간이 두 배로 줄었어요..!! 감사합니다!

@sforseohn
Copy link
Author

sforseohn commented Jun 2, 2023

리뷰 해주신대로 수정하여 제출했습니다! 마지막까지 감사합니다 ❤

Copy link
Contributor

@jk0527 jk0527 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[최단 경로 구현 문제 추가 제출 확인 완료]

추가 제출 확인했습니다!🥰🥰
수고하셨습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants