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

6-yuyu0830 #26

Merged
merged 2 commits into from
Apr 8, 2024
Merged

6-yuyu0830 #26

merged 2 commits into from
Apr 8, 2024

Conversation

yuyu0830
Copy link
Collaborator

@yuyu0830 yuyu0830 commented Apr 3, 2024

πŸ”— 문제 링크

λ‚˜λ§Œ μ•ˆλ˜λŠ” μ—°μ• (14621)

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

1μ‹œκ°„ 반

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

μ΅œμ†Œ μ‹ μž₯ 트리λ₯Ό μ‚¬μš©ν•˜λŠ” λ¬Έμ œμž…λ‹ˆλ‹€.
쑰금 λ‹€λ₯Έ 점이 μžˆλ‹€λ©΄ μ •μ μœΌλ‘œ μ œκ³΅λ˜λŠ” 'λŒ€ν•™κ΅' κ°€ 'μ—¬μ΄ˆ λŒ€ν•™κ΅'와 'λ‚¨μ΄ˆ λŒ€ν•™κ΅' 둜 λ‚˜λ‰˜κ³ , ν•œ ν•™κ΅μ—μ„œ λ‹€λ₯Έ ν•™κ΅λ‘œ 갈 λ•Œ μ„œλ‘œ μƒλ°˜λœ ν•™κ΅λ‘œλ§Œ 갈 수 μžˆμŠ΅λ‹ˆλ‹€.

μš°μ„  문제의 해결은 Kruskal μ•Œκ³ λ¦¬μ¦˜μ„ μ‚¬μš©ν–ˆμŠ΅λ‹ˆλ‹€. οΏ½λͺ¨λ“  정점을 λ°©λ¬Έν•˜λŠ” μ΅œμ†Œ 거리λ₯Ό ꡬ할 λ•Œ, 간선을 길이 κΈ°μ€€μœΌλ‘œ μ •λ ¬ν•΄ 짧은 κ°„μ„ λΆ€ν„° ν•˜λ‚˜μ”© μ μš©ν•˜λ©° μ΅œμ†Œ 거리λ₯Ό κ΅¬ν•©λ‹ˆλ‹€.
이 λ•Œ, λ¬΄μž‘μ • μ μš©ν•˜λŠ”κ²Œ μ•„λ‹Œ '사이클이 μƒκΈ°λŠ”μ§€ 체크' ν•˜λ©° 탐색해야 ν•©λ‹ˆλ‹€. 사이클은 Union-Find μ•Œκ³ λ¦¬μ¦˜μ„ 톡해 체크할 수 μžˆμŠ΅λ‹ˆλ‹€.

ν•˜μ§€λ§Œ 이번 λ¬Έμ œλŠ” 'μ—¬μ΄ˆ λŒ€ν•™κ΅' 와 'λ‚¨μ΄ˆ λŒ€ν•™κ΅' λ¬Έμ œκ°€ μƒκΉλ‹ˆλ‹€. κ·Έλž˜μ„œ μ²˜μŒμ—λŠ” 정점끼리 Union 비ꡐλ₯Ό ν•  λ•Œ λ‚¨μ΄ˆ μ—¬μ΄ˆ μ—¬λΆ€λ₯Ό ν™•μΈν•˜λ € ν–ˆμŠ΅λ‹ˆλ‹€. 그런데 κ΅¬ν˜„ν•˜λ‹€ λ³΄λ‹ˆ μž…λ ₯을 받을 λ•Œ λΆ€ν„° κ±ΈλŸ¬λ‚Έλ‹€λ©΄ μ‹€ν–‰ μ‹œκ°„μ„ 쀄일 수 μžˆκ² κ΅¬λ‚˜ μ‹Άμ–΄ manOnly 배열을 톡해 μž…λ ₯ λ°›λŠ” μ‹œμ μ—μ„œ ν•΄κ²°ν–ˆμŠ΅λ‹ˆλ‹€.

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

μ΅œμ†Œ μ‹ μž₯ νŠΈλ¦¬κ°€ μ–΄λ–»κ²Œ κ΅¬ν˜„λ˜κ³ , kruskal μ•Œκ³ λ¦¬μ¦˜μ€ μ–΄λ–»κ²Œ μ‚¬μš©ν•˜λŠ”μ§€ κ³΅λΆ€ν–ˆμŠ΅λ‹ˆλ‹€. Union-Find μž¬λ°Œλ„€μš” γ…Žγ…Ž

@yuyu0830 yuyu0830 self-assigned this Apr 3, 2024
@InSange InSange changed the title 24-04-03 λ‚˜λ§Œ μ•ˆλ˜λŠ” μ—°μ•  6-yuyu0830 Apr 3, 2024
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.

λ‚¨μž μ—¬μžλ§Œ ꡬ뢄해주면 κ·Έ ν›„λ‘  λ‹¨μˆœ MSTλΌμ„œ μš°μ„  μˆœμœ„νμ— κ°€κΉŒμš΄ λ…Έλ“œλ“€μ„ 이어주면 λμ΄λ„€μš©!
μ–΄μ°Œλ³΄λ©΄ MSTλŠ” μ‘°κ±΄λ“€λ§Œ λ§Œμ‘±ν•˜λ©΄ κ°€μž₯ λ‹¨μˆœν•œ λ¬Έμ œκ°€ μ•„λ‹κΉŒμš”?

@yuyu0830
Copy link
Collaborator Author

yuyu0830 commented Apr 4, 2024

λ‚¨μž μ—¬μžλ§Œ ꡬ뢄해주면 κ·Έ ν›„λ‘  λ‹¨μˆœ MSTλΌμ„œ μš°μ„  μˆœμœ„νμ— κ°€κΉŒμš΄ λ…Έλ“œλ“€μ„ 이어주면 λμ΄λ„€μš©! μ–΄μ°Œλ³΄λ©΄ MSTλŠ” μ‘°κ±΄λ“€λ§Œ λ§Œμ‘±ν•˜λ©΄ κ°€μž₯ λ‹¨μˆœν•œ λ¬Έμ œκ°€ μ•„λ‹κΉŒμš”?

사싀 μž…λ ₯ 받을 λ•Œ 처리만 ν•˜κ³  λ‚˜λ‹ˆ MSTλž‘ λ‹€λ₯Όκ²Œ ν•˜λ‚˜λ„ μ—†μ—ˆμ–΄μš”... 그런 μ˜λ―Έμ—μ„œλŠ” κΏ€λ¬Έμ œκ°€ μ•„λ‹ˆμ˜€μ„κΉŒμš”?

Copy link
Collaborator

@seongwon030 seongwon030 left a comment

Choose a reason for hiding this comment

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

μž…λ ₯λΆ€ν„° 같은 성별이면 걸러주고 κ·Έ ν›„μ—” λ˜‘κ°™μ΄ 크루슀칼둜 μ§„ν–‰ν•˜λ©΄ λ˜λŠ” λ¬Έμ œμ˜€λ„€μš©. λ§Œμ•½ μ•ˆ κ±°λ₯΄κ³  ν•œλ‹€λ©΄ 비ꡐ할 λ•Œλ§ˆλ‹€ μ„œλ‘œ λ‹€λ₯Έ 성별인지 ν™•μΈν•΄μ•Όν•˜λ‹ˆκΉŒ ν™•μ‹€νžˆ 더 쒋은 ν•΄κ²°λ²•μ΄μ—ˆλ‹€λŠ” 생각이 λ“­λ‹ˆλ‹€. 잘 λ΄€μŠ΅λ‹ˆλ‹€ γ…Žγ…Ž

Copy link
Contributor

@dhlee777 dhlee777 left a comment

Choose a reason for hiding this comment

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

μ²˜μŒμž…λ ₯ λ°›μ„λ•ŒλΆ€ν„° manonly 배열을 톡해 λ‚¨μžλŠ” 1둜 μ„€μ •ν•΄μ£Όλ©° λ‚¨μž-μ—¬μžμΌ 경우만 벑터에 λ„£μ–΄μ£ΌλŠ”κ΅°μš” μ €κ°™μœΌλ©΄ λ‚˜μ€‘μ— νƒμƒ‰κ³Όμ •μ—μ„œ κ±ΈλŸ¬λƒˆμ„κ±° 같은데 μ‹ κΈ°ν•˜λ„€μš”..
그리고 ꡬ쑰체 ν™œμš©μ— λŒ€ν•΄μ„œλ„ 잘 λ°°μ›Œκ°‘λ‹ˆλ‹€..!

@yuyu0830 yuyu0830 merged commit 615bc15 into main Apr 8, 2024
1 check passed
@yuyu0830 yuyu0830 deleted the 6-yuyu0830 branch April 8, 2024 11:49
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.

5 participants