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

20-seongwon030 #76

Merged
merged 1 commit into from
Jul 23, 2024
Merged

20-seongwon030 #76

merged 1 commit into from
Jul 23, 2024

Conversation

seongwon030
Copy link
Collaborator

πŸ”— 문제 링크

μ§‘ν•©μ˜ ν‘œν˜„

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

15λΆ„

✨ μˆ˜λ„ μ½”λ“œ

μ΅œμ†Œ μ‹ μž₯ νŠΈλ¦¬μ—μ„œ μ‚¬μš©ν•œ μ•Œκ³ λ¦¬μ¦˜κ³Ό 거의 λ™μΌν•΄μ„œ ν‘ΈλŠ”λ° 많이 걸리지 μ•Šμ•˜μŠ΅λ‹ˆλ‹€.

  1. 0일 λ•ŒλŠ” union연산을 μ§„ν–‰ν•œλ‹€.
def union(x,y):
  x,y = find(x),find(y)
  if x<y:
    parent[x] = y
  else:
    parent[y] = x

각 μ›μ†Œμ˜ 루트 λ…Έλ“œλ₯Ό μ°Ύμ•„ λΉ„κ΅ν•˜λ©΄μ„œ 두 μ›μ†Œλ₯Ό ν•˜λ‚˜λ‘œ ν•©μΉ˜λŠ” 합집합 μ—°μ‚°

  1. 1일 λ•ŒλŠ” 두 μ›μ†Œκ°€ ν•œ 집합에 ν¬ν•¨λ˜λŠ”μ§€ ν™•μΈν•œλ‹€.
def find(x):
  if x!=parent[x]:
    parent[x] = find(parent[x])
  return parent[x]

λ£¨νŠΈλ…Έλ“œκ°€ κ°™μœΌλ©΄ ν•œ 집합에 ν¬ν•¨λ˜λ―€λ‘œ YESλ₯Ό 좜λ ₯, μ•„λ‹ˆλ©΄ Noλ₯Ό 좜λ ₯ν•œλ‹€.

Copy link
Collaborator

@yuyu0830 yuyu0830 left a comment

Choose a reason for hiding this comment

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

이걸둜 μ–Όλ§ˆλ‚˜ ν•΄λ¨ΉλŠ”κ±°μ•Ό γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹

@seongwon030
Copy link
Collaborator Author

이걸둜 μ–Όλ§ˆλ‚˜ ν•΄λ¨ΉλŠ”κ±°μ•Ό γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹

λ‹€μ–‘ν•œ 문제λ₯Ό 풀도둝 ν•˜κ² μŠ΅λ‹ˆλ‹· ..

Copy link
Collaborator

@yuyu0830 yuyu0830 left a comment

Choose a reason for hiding this comment

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

백쀀에 μœ λ‹ˆμ˜¨ νŒŒμΈλ“œλž‘ MST κ΄€λ ¨λœ λ¬Έμ œλŠ” μ „λΆ€ λ‹€ ν’€ κΈ°μ„Έκ΅°μš”.. 저도 ν•œμ°½ BFS λΉ μ Έμžˆμ„ λ•Œ κ·Έλ ‡κ²Œ ν’€μ—ˆλ˜κ²Œ κΈ°μ–΅λ‚˜λŠ”λ° ν™•μ‹€νžˆ κ·Έ μ•Œκ³ λ¦¬μ¦˜μ€ 평생 κΉŒλ¨Ήμ§„ μ•Šκ² λ”λΌκ΅¬μš”. 근데 μœ λ‹ˆμ˜¨ νŒŒμΈλ“œλŠ” λ²”μš©μ„±μ΄ 그리 넓은 μ•Œκ³ λ¦¬μ¦˜μ€ μ•„λ‹ˆλ‹ˆ λ‹€μ–‘ν•œ μ•Œκ³ λ¦¬μ¦˜λ„ λ„μ „ν•΄λ³΄λŠ”κ±΄ μ–΄λ–¨κΉŒμš”?

@seongwon030
Copy link
Collaborator Author

백쀀에 μœ λ‹ˆμ˜¨ νŒŒμΈλ“œλž‘ MST κ΄€λ ¨λœ λ¬Έμ œλŠ” μ „λΆ€ λ‹€ ν’€ κΈ°μ„Έκ΅°μš”.. 저도 ν•œμ°½ BFS λΉ μ Έμžˆμ„ λ•Œ κ·Έλ ‡κ²Œ ν’€μ—ˆλ˜κ²Œ κΈ°μ–΅λ‚˜λŠ”λ° ν™•μ‹€νžˆ κ·Έ μ•Œκ³ λ¦¬μ¦˜μ€ 평생 κΉŒλ¨Ήμ§„ μ•Šκ² λ”λΌκ΅¬μš”. 근데 μœ λ‹ˆμ˜¨ νŒŒμΈλ“œλŠ” λ²”μš©μ„±μ΄ 그리 넓은 μ•Œκ³ λ¦¬μ¦˜μ€ μ•„λ‹ˆλ‹ˆ λ‹€μ–‘ν•œ μ•Œκ³ λ¦¬μ¦˜λ„ λ„μ „ν•΄λ³΄λŠ”κ±΄ μ–΄λ–¨κΉŒμš”?

ν•˜λ‚˜λ₯Ό νŒŒλ‹€λ³΄λ‹ˆ 풀이방법이 λ‹€ λΉ„μŠ·ν•˜λ”λΌκ³ μš”. ν•œ 번 ν’€μ–΄λ³Έ λ¬Έμ œκ°€ 기얡이 μ•ˆ λ‚˜μ„œ κΈ°μ–΅ν•  κ²Έ μ΄κ²ƒλ§Œ ν’€κ³  μžˆμ—ˆλŠ”λ° λ§μ”€ν•˜μ‹  κ²ƒμ²˜λŸΌ λ‹€μ–‘ν•œ μ•Œκ³ λ¦¬μ¦˜μ„ ν‘ΈλŠ” 것도 μ€‘μš”ν•˜κ² λ„€μš”! λ‹€μ–‘ν•œ μ•Œκ³ λ¦¬μ¦˜μ— λ„μ „ν•΄λ³΄κ² μ”λ‹ˆλ‹Ή

Copy link
Collaborator

@InSange InSange left a comment

Choose a reason for hiding this comment

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

Union Findλ₯Ό 잘 ν™œμš©μ„ μ•ˆν•˜λŠ” μ΄μœ κ°€ 연결은 μ‰½μ§€λ§Œ λΆ„λ¦¬ν•˜λŠ”κ²Œ κΉŒλ‹€λ‘œμš΄ μ΄μœ κ°€ μ»€μ„œ 그렇지 μ•Šμ„κΉŒ μ‹ΆμŠ΅λ‹ˆλ‹€. Unionκ³Ό Find ν•¨μˆ˜λŠ” ν˜ΈμΆœμ‹œμ— μ΅œμƒμœ„ λ…Έλ“œλ‘œ 값을 κ°±μ‹ ν•˜λŠ” μž‘μ—…μ„ 거치게 λ˜λ‹€λ³΄λ‹ˆ 좔후에 뢄리할 μ‹œμ— μ—°κ²°λ˜μ–΄ μžˆλŠ” ν•˜μœ„ λ…Έλ“œλ“€μ„ λ‹€ κ°±μ‹ μ‹œμΌœμ£ΌλŠ” μž‘μ—…μ—μ„œ 보닀 λΉ„νš¨μœ¨μ μ΄μ–΄μ„œ 그렇지 μ•Šμ„κΉŒ μ‹Άλ„€μš”.

κ²Œμž„μ—μ„œλ„ ν•˜λ‚˜μ˜ 데이터에 μ—°κ΄€μžˆλŠ” 데이터듀을 μ°Ύκ³  싢을 λ•Œ κ°„ν˜Ή 쓰이긴 ν•˜λ”κ΅°μš”. 같은 μ†Œμ†μ— μ‘΄μž¬ν•˜λŠ”μ§€. 이동가λŠ₯ν•œ 경둜λ₯Ό λΉ λ₯΄κ²Œ μ°Ύκ³  싢을 λ•Œ ( κ°„ν˜Ή μ²΄μŠ€μ™€ 같은? )

@seongwon030
Copy link
Collaborator Author

Union Findλ₯Ό 잘 ν™œμš©μ„ μ•ˆν•˜λŠ” μ΄μœ κ°€ 연결은 μ‰½μ§€λ§Œ λΆ„λ¦¬ν•˜λŠ”κ²Œ κΉŒλ‹€λ‘œμš΄ μ΄μœ κ°€ μ»€μ„œ 그렇지 μ•Šμ„κΉŒ μ‹ΆμŠ΅λ‹ˆλ‹€. Unionκ³Ό Find ν•¨μˆ˜λŠ” ν˜ΈμΆœμ‹œμ— μ΅œμƒμœ„ λ…Έλ“œλ‘œ 값을 κ°±μ‹ ν•˜λŠ” μž‘μ—…μ„ 거치게 λ˜λ‹€λ³΄λ‹ˆ 좔후에 뢄리할 μ‹œμ— μ—°κ²°λ˜μ–΄ μžˆλŠ” ν•˜μœ„ λ…Έλ“œλ“€μ„ λ‹€ κ°±μ‹ μ‹œμΌœμ£ΌλŠ” μž‘μ—…μ—μ„œ 보닀 λΉ„νš¨μœ¨μ μ΄μ–΄μ„œ 그렇지 μ•Šμ„κΉŒ μ‹Άλ„€μš”.

κ²Œμž„μ—μ„œλ„ ν•˜λ‚˜μ˜ 데이터에 μ—°κ΄€μžˆλŠ” 데이터듀을 μ°Ύκ³  싢을 λ•Œ κ°„ν˜Ή 쓰이긴 ν•˜λ”κ΅°μš”. 같은 μ†Œμ†μ— μ‘΄μž¬ν•˜λŠ”μ§€. 이동가λŠ₯ν•œ 경둜λ₯Ό λΉ λ₯΄κ²Œ μ°Ύκ³  싢을 λ•Œ ( κ°„ν˜Ή μ²΄μŠ€μ™€ 같은? )

였호 λ‹€μ‹œ λΆ„λ¦¬ν•˜λŠ” κ²½μš°κ°€ κΉŒλ‹€λ‘œμ›Œμ„œ μœ λ‹ˆμ˜¨νŒŒμΈλ“œλ₯Ό 잘 쓰지 μ•ŠλŠ”κ±°κ΅°μš”. λ‹€μ‹œ κ°±μ‹ ν•΄μ£ΌλŠ” μž‘μ—…μ΄ ν•„μš”ν•˜λ‹ˆκΉŒ λ²ˆκ±°λ‘­λ„€μš”. κ²Œμž„μ—μ„œλŠ” 그런 μ•Œκ³ λ¦¬μ¦˜μ΄ μ‹€μ œλ‘œ μ‚¬μš©λ˜κΈ°λ„ ν•˜λŠ”κ΅°μš”. μ˜ˆκΉŒμ§€ λ“€μ–΄μ£Όμ…”μ„œ λ°”λ‘œ 이해가 λ˜μ—ˆμŠ΅λ‹ˆλ‹€ πŸ˜€

@seongwon030 seongwon030 merged commit f87df67 into main Jul 23, 2024
1 check passed
@seongwon030 seongwon030 deleted the 20-seongwon030 branch July 23, 2024 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants