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

7-Me-in-U #22

Merged
merged 3 commits into from
Jul 18, 2024
Merged

7-Me-in-U #22

merged 3 commits into from
Jul 18, 2024

Conversation

Me-in-U
Copy link
Collaborator

@Me-in-U Me-in-U commented May 22, 2024

πŸ”— 문제 링크

2150번 Strongly Connected Component

✨ 문제 풀이

SCC, κ°•ν•œ μ—°κ²° μš”μ†Œλž€ 유ν–₯ κ·Έλž˜ν”„μ—μ„œ λͺ¨λ“  정점이 λͺ¨λ“  λ‹€λ₯Έ 정점에 λŒ€ν•΄ 도달 κ°€λŠ₯ν•œ 경우λ₯Ό λœ»ν•œλ‹€.
image
μœ„ λ°©ν–₯ κ·Έλž˜ν”„λ₯Ό 예λ₯Ό λ“€μ–΄ μ„€λͺ…ν•˜λ©΄
{a, b, c}, {d}, {e}둜 κ°•ν•œ μ—°κ²° μš”μ†Œ κ·Έλž˜ν”„λ₯Ό λ‚˜λˆŒ 수 μžˆλ‹€.
aμ—μ„œ b와 c둜 갈 수 있고
bμ—μ„œ a와 c둜 갈 수 있고
cμ—μ„œ a와 b둜 갈 수 μžˆλ‹€

cμ—μ„œ dλ‘œλŠ” 갈 수 μžˆμ§€λ§Œ dμ—μ„œ cλ‘œλŠ” λͺ»κ°„λ‹€.
μ΄λŸ°κ²ƒλ“€μ€ μ•½ν•œ 연결이라고 ν•œλ‹€.


주어진 λ°©ν–₯ κ·Έλž˜ν”„μ—μ„œ SCCλ₯Ό κ΅¬ν•˜λŠ” μ•Œκ³ λ¦¬μ¦˜μœΌλ‘œ Kosaraju(코살라주)와 Tarjan(νƒ€μž”) μ•Œκ³ λ¦¬μ¦˜μ΄ μžˆλ‹€.
이 λ¬Έμ œλŠ” 코사라주 μ•Œκ³ λ¦¬μ¦˜μ„ ν’€μ—ˆλ‹€.

  • 코사라주 μ•Œκ³ λ¦¬μ¦˜
    주어진 λ°©ν–₯ κ·Έλž˜ν”„μ˜ μ—­λ°©ν–₯ κ·Έλž˜ν”„μ™€ μŠ€νƒμ„ μ‚¬μš©ν•˜μ—¬ SCCλ₯Ό κ΅¬ν•˜λŠ” μ•Œκ³ λ¦¬μ¦˜μ΄λ‹€.
    이 μ•Œκ³ λ¦¬μ¦˜μ€ μ—­λ°©ν–₯ κ·Έλž˜ν”„(λͺ¨λ“  κ°„μ„ λ“€μ˜ λ°©ν–₯을 뒀집은 κ·Έλž˜ν”„)κ°€ μ›λž˜ κ·Έλž˜ν”„μ™€ μ •ν™•νžˆ 같은 κ°•ν•œ μ—°κ²° μš”μ†Œλ₯Ό κ°–λŠ”λ‹€λŠ” 사싀을 μ΄μš©ν•œλ‹€.

β‘  μ£Όμ–΄μ§€λŠ” λ°©ν–₯ κ·Έλž˜ν”„μ™€ κ·Έ κ·Έλž˜ν”„μ˜ μ—­λ°©ν–₯ κ·Έλž˜ν”„λ₯Ό λ§Œλ“ λ‹€.
β‘‘ 정점을 담을 μŠ€νƒμ„ λ§Œλ“€κ³  μž„μ˜μ˜ 정점뢀터 λ°©ν–₯ κ·Έλž˜ν”„μ—μ„œ DFSλ₯Ό μˆ˜ν–‰ν•œλ‹€.
β‘’ DFSκ°€ λλ‚˜λŠ” μˆœμ„œλŒ€λ‘œ μŠ€νƒμ— μ‚½μž…ν•˜κ³ , 아직 λ°©λ¬Έν•˜μ§€ μ•Šμ€ 정점에 λŒ€ν•΄ DFSλ₯Ό μˆ˜ν–‰ν•œλ‹€.
β‘£ λͺ¨λ“  정점이 μŠ€νƒμ— λ‹΄κΈ΄ ν›„μ—λŠ” μŠ€νƒμ„ popν•˜μ—¬ λ‚˜μ˜€λŠ” 정점쀑 λ°©λ¬Έν•˜μ§€ μ•Šμ€ 정점을 μ—­λ°©ν–₯ κ·Έλž˜ν”„μ—μ„œ DFSλ₯Ό μˆ˜ν–‰ν•œλ‹€.
β‘€ μ΄λ•Œ νƒμƒ‰λ˜λŠ” λͺ¨λ“  정점을 SCC둜 λ¬ΆλŠ”λ‹€.
이것을 μŠ€νƒμ΄ 빌 λ•ŒκΉŒμ§€ μ§„ν–‰ν•œλ‹€


μ˜ˆμ‹œ μ„€λͺ…

μ•„λž˜μ™€ 같은 κ·Έλž˜ν”„κ°€ μžˆλ‹€.
μŠ€ν¬λ¦°μƒ· 2024-05-23 022844

  • μŠ€νƒ, μ—­λ°©ν–₯ κ·Έλž˜ν”„λ₯Ό λ§Œλ“€μ–΄ μ€€λ‹€.
    0

  • 주어진 λ°©ν–₯ κ·Έλž˜ν”„μ—μ„œ DFS
    ezgif-7-f27873f6ec
    그러면
    d, g, c, b, a, f, h, e μˆœμ„œλŒ€λ‘œ μŠ€νƒμ— λ“€μ–΄κ°„λ‹€.

  • μŠ€νƒμ—μ„œ popν•˜λ©΄μ„œ μ—­λ°©ν–₯ κ·Έλž˜ν”„μ—μ„œ dfs
    ezgif-7-25f1b9ce4b

  • κ²°κ³Ό
    μ•„λž˜μ™€ 같은 3개의 그룹이 λ§Œλ“€μ–΄ 진닀.!
    image

Copy link
Collaborator

@wjdheesp44 wjdheesp44 left a comment

Choose a reason for hiding this comment

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

dfs와 μŠ€νƒμ„ ν™œμš©ν•˜μ—¬ λ§Œλ“œλŠ” μ•Œκ³ λ¦¬μ¦˜μ΄λ„€μš”. 처음 λ³Ό λ•ŒλŠ” μ–΄λ €μ›Œ λ³΄μ—¬μ„œ λ‹€λ₯Έ μ‚¬λžŒ μ½”λ“œ, λΈ”λ‘œκ·Έ λ³΄λ©΄μ„œ μ§œλ΄€λŠ”λ° 짜고 λ³΄λ‹ˆ μƒκ°λ³΄λ‹€λŠ” κ°„λ‹¨ν•œ 것 κ°™μ•„μš”! μˆ˜κ³ ν•˜μ…¨μŠ΅λ‚˜λ‹€.

Copy link
Collaborator

@erase-jeong erase-jeong left a comment

Choose a reason for hiding this comment

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

κ°•ν•œμ—°κ²°κ΄€κ³„ (scc) μ΄μ‚°μˆ˜ν•™μ‹œκ°„μ— λ°°μ› λ˜κ²ƒ 같은데 λ°˜κ°‘λ„€μš”.
덕뢄에 코살라주 μ•Œκ³ λ¦¬μ¦˜ λ°°μ›Œκ°€λ„€μš”

@Me-in-U Me-in-U merged commit 5201143 into main Jul 18, 2024
@Me-in-U Me-in-U deleted the 7-Me-in-U branch July 18, 2024 17:29
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