Skip to content

BOJ9372_상근이의_여행_실버4_권은홍 #32

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

96Hong2
Copy link
Owner

@96Hong2 96Hong2 commented Mar 3, 2024

간선이 가장 적게 하여 모든 정점을 탐색하는 알고리즘 >> 방향과 가중치가 없는 크루스칼 알고리즘 구현

  1. Graph 스태틱 클래스 생성
    1-1. int v 정점의 수, parents[v+1] 배열 생성
    1-2. initGraph(int v) 함수 : parents[v+1]의 각각의 값에 자기 자신 입력
    1-3. find 함수 : 정점의 부모를 찾아서 자기 자신이면 return하고, 아니면 그 부모의 부모를 찾는 재귀함수
    1-4. union 함수 : find로 정점의 부모를 찾아서 서로 같으면 -1을 리턴하고, 서로 다를 때 더 작은 수를 공통부모로 만드는 함수. 부모가 된 수를 리턴
  2. 테스트 케이스 T 받아서 반복
  3. Scanner로 국가(정점)의 수 N, 비행기 종류(간선)의 수 M 받기, int result = 0;
  4. Graph생성 후 setGraph(N) 으로 그래프 초기화
  5. M만큼 돌며 시작정점 v1, 도착정점v2를 받아 union 함수를 돌려서 -1이 나오면 continue, 아니면 result++;
  6. M번 다 돌았으면 result 출력

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.

1 participant