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

19-seongwon030 #73

Merged
merged 1 commit into from
Jul 22, 2024
Merged

19-seongwon030 #73

merged 1 commit into from
Jul 22, 2024

Conversation

seongwon030
Copy link
Collaborator

@seongwon030 seongwon030 commented Jul 14, 2024

πŸ”— 문제 링크

μ „λ ₯λ‚œ

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

2μ‹œκ°„

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

λ£¨νŠΈλ…Έλ“œ μ°ΎκΈ°

def find(x):
  if x!=root[x]:
    root[x] = find(root[x])
  return root[x]

두 개의 λ…Έλ“œ ν•©μΉ˜κΈ°

def union(x,y):
  x,y = find(x),find(y)
  if x<y:
    root[y] = x
  else:
    root[x] = y

μœ„ 두가지 ν•¨μˆ˜λ₯Ό μ΄μš©ν•΄μ„œ 문제λ₯Ό ν’€μ—ˆμŠ΅λ‹ˆλ‹€. 사싀 μ €λ²ˆμ— ν‘Ό 문제λ₯Ό λΉ„μŠ·ν–ˆλŠ”λ° μ’€ ν—€λ§ΈμŠ΅λ‹ˆλ‹€. μ΅œμ†Œμ‹ μž₯트리 λΉ„μš©μ΄ μ•„λ‹ˆλΌ κ°€λ‘œλ“±μ˜ λΆˆμ„ μ•„λ‚€ λΉ„μš©μ„ 계산해야 ν•˜λŠ” λ¬Έμ œμ˜€μŠ΅λ‹ˆλ‹€.

for a,b,c in edge:
    aRoot = find(a)
    bRoot = find(b)
    if aRoot != bRoot: # 이어지지 μ•ŠμŒ (사이클이 μ—†λ‹€)
      union(aRoot,bRoot)
    else: # 이어짐 (μ ˆμ•½ν•  수 μžˆλ‹€)
      ans+=c 
  1. 사이클이 μ—†λŠ” 경우 이어지지 μ•Šμ•˜μœΌλ―€λ‘œ 두 정점을 μ΄μ–΄μ€λ‹ˆλ‹€.
  2. 사이클이 μžˆλ‹€λ©΄ μ ˆμ•½ν•  수 있기 λ•Œλ¬Έμ— κ·ΈλŒ€λ‘œ λΉ„μš©μ„ λ”ν•΄μ€λ‹ˆλ‹€.

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

문제λ₯Ό 잘 읽자.

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.

μ ˆμ•½ν•œ λΉ„μš© = μ΅œμ†Œ λΉ„μš© μ΄λž‘ λ˜‘κ°™μ€κ²Œ μ•„λ‹Œκ°€μš©?
λ”±νžˆ μ˜ˆμ™Έ μ²˜λ¦¬λ„ μ—†λŠ”κ²ƒκ°™μ•„ λ³΄μ΄λŠ”λ°..

@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.

λ‹€μ–‘ν•œ λ¬Έμ œμ’€ ν’€μ–΄!

@seongwon030
Copy link
Collaborator Author

λ‹€μ–‘ν•œ λ¬Έμ œμ’€ ν’€μ–΄!

λ‹€μŒμ—” λ‹€λ₯Έ κ±° ν’€μ–΄λ³Όκ²Œμš” γ…Žγ…Ž..

@seongwon030 seongwon030 merged commit 8b757c8 into main Jul 22, 2024
1 check passed
@seongwon030 seongwon030 deleted the 19-seongwon030 branch July 22, 2024 14:53
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