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

[최단경로] 2171024 신수정 #362

Open
wants to merge 32 commits into
base: 2171024-신수정2
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
de9881a
[4월 12일] 동적 계획법 강의 자료 업로드
jk0527 Apr 12, 2023
8ef72d6
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 Apr 12, 2023
6223f7e
[4월 12일] 동적 계획법 리드미 업로드
jk0527 Apr 12, 2023
da38b52
[4월 14일] 동적 계획법 강의 자료 수정
jk0527 Apr 14, 2023
53b5bfa
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 Apr 14, 2023
3a83c8a
[4월 14일] 리드미 수정
jk0527 Apr 14, 2023
149f4c0
[4월 14일] 동적 계획법 라이브코딩 코드 업로드
jk0527 Apr 14, 2023
1d0e018
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 Apr 14, 2023
1bcacb0
[4월 14일] 동적 계획법 리드미 수정
jk0527 Apr 14, 2023
cbdb583
[5월 2일] 동적 계획법 강의자료 수정
jk0527 May 1, 2023
c2091d7
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 May 1, 2023
1b3b114
[5월 2일] 백트래킹 과제 코드 업로드
jk0527 May 1, 2023
86da014
[5월 2일] 동적 계획법 과제 코드 업로드
jk0527 May 1, 2023
bd2b014
[5월 2일] 백트래킹 리드미 수정
jk0527 May 1, 2023
d51f618
[5월 2일] 동적 계획법 리드미 수정
jk0527 May 1, 2023
93c419c
[5월 5일] 이분 탐색 리드미 업로드
jk0527 May 5, 2023
88830b6
[5월 5일] 이분 탐색 강의 자료 업로드
jk0527 May 5, 2023
5a6372c
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 May 5, 2023
ad6eebb
[5월 5일] 이분 탐색 라이브 코딩 코드 업로드
jk0527 May 5, 2023
9f9b791
[5월 5일] 이분 탐색 리드미 수정
jk0527 May 5, 2023
3a55ea1
[5월 5일] 리드미 수정
jk0527 May 5, 2023
cedeb06
[5월 9일] 이분 탐색 과제 코드 업로드
jk0527 May 9, 2023
7699152
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 May 9, 2023
bbfbc93
[5월 9일] 투 포인터 리드미 업로드
jk0527 May 9, 2023
7baa1de
[5월 10일] 이분 탐색 리드미 수정
jk0527 May 10, 2023
b6f7843
[5월 10일] 투 포인터 강의 자료 업로드
jk0527 May 10, 2023
b92e936
Merge branch 'main' of https://github.com/Altu-Bitu-Official/Altu-Bitu-4
jk0527 May 10, 2023
56d70ae
[5월 10일] 리드미 수정
jk0527 May 10, 2023
3549143
[0523] 트리 -필수문제
chock-cho May 23, 2023
0a250a4
[0523] 트리-필수문
chock-cho May 23, 2023
de869b8
[0530] 최단경로
chock-cho May 30, 2023
fe3f732
[0530] 최단경로
chock-cho May 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions 13_최단 경로/필수/2458..cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 2458
// 플로이드-워셜 알고리즘 이용

#include <iostream>
#include <algorithm>
#include <vector>

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

Choose a reason for hiding this comment

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

이렇게 선언하니까 좋네요!! 배워갑니다~


void floydWarShall(int N, vector<vector<int>> &adj){
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
for(int k = 1; k <= N; k++){
if(adj[j][i] && adj[i][k]) {
adj[j][k] = CONNECT;
}
}
}
}
}

int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int N, M, x, y;
cin >> N >> M;
vector<vector<int>> adj(N+1, vector<int>(N+1, 0));
while(M--){
cin >> x >> y;
adj[x][y] = CONNECT;
}
floydWarShall(N, adj);
// 답 얻어내기
int answer = 0;
for(int i = 1; i <= N; i++){
int connected_student = 0;
for(int j = 1; j <= N; j++) {
if(adj[i][j] == CONNECT || adj[j][i] == CONNECT) {
connected_student++; // 자신을 제외한 N-1명 학생이 연결돼있나?

if(connected_student >= N-1) { // N-1명 이상이 연결되어있음
answer++;
}
}
}
}
Comment on lines +35 to +46
Copy link
Contributor

@Dong-droid Dong-droid May 31, 2023

Choose a reason for hiding this comment

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

P3. if(connected_student == N-1) 이어도 될 것 같아요~ 여기 부분 잘하셨네요!! 👍 👍

cout << answer << "\n";

}