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

10-mong3125 #35

Merged
merged 1 commit into from
Mar 18, 2024
Merged

10-mong3125 #35

merged 1 commit into from
Mar 18, 2024

Conversation

mong3125
Copy link
Collaborator

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

ํŠธ๋ฆฌ์˜ ์ง€๋ฆ„

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

ํ•ด๊ฒฐ ๋ชปํ•˜๊ณ  ํ•ต์‹ฌ ์•„์ด๋””์–ด๋ฅผ ์ฐธ๊ณ ํ–ˆ์Šต๋‹ˆ๋‹ค.
์•„์ด๋””์–ด๋ฅผ ๋ณด๊ณ  ๋‚˜์„œ 20๋ถ„ ์ •๋„ ๊ฑธ๋ฆฐ ๊ฒƒ ๊ฐ™์•„์š”.

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

ํ•ต์‹ฌ ์•„์ด๋””์–ด

ํŠธ๋ฆฌ์˜ ์ง€๋ฆ„ ์„ค๋ช…
์œ„์— ์‚ฌ์ดํŠธ์—์„œ ํ•ต์‹ฌ ์•„์ด๋””์–ด๋ฅผ ์–ป๊ณ  ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.

๊ทผ๊ฑฐ๋ฅผ ๋นผ๊ณ  ์š”์•ฝ์„ ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
-> ์–ด๋–ค ํ•œ ๋…ธ๋“œ๋กœ๋ถ€ํ„ฐ ๊ฐ€์žฅ ๋ฉ€๋ฆฌ์žˆ๋Š” ๋…ธ๋“œ๋Š” ํŠธ๋ฆฌ์˜ ์ง€๋ฆ„์˜ ์–‘ ๋์ค‘ ํ•˜๋‚˜์ด๋‹ค.
-> ํŠธ๋ฆฌ์˜ ์ง€๋ฆ„์˜ ์–‘ ๋์ค‘ ํ•˜๋‚˜์—์„œ ๊ฐ€์žฅ ๋ฉ€๋ฆฌ์žˆ๋Š” ๋…ธ๋“œ๋Š” ํŠธ๋ฆฌ์˜ ์ง€๋ฆ„ ์–‘๋ ์ค‘ ๋‹ค๋ฅธ ํ•˜๋‚˜์ด๋‹ค.

๋ฌธ์ œ ํ•ด๊ฒฐ

// DFS ๋ฐฉ์‹์œผ๋กœ ํ•œ ๋…ธ๋“œ์—์„œ ์ถœ๋ฐœํ•ด ์—ฃ์ง€์˜ ๋, ๋ฆฌํ”„๊นŒ์ง€ ์ „๋ถ€ ํƒ์ƒ‰์„ ํ•˜๋ฉด์„œ ๊ฐ€์žฅ ๋จผ ๋…ธ๋“œ๋ฅผ ์ฐพ์Šต๋‹ˆ๋‹ค.
dfs(int node, int cost) {
    ๋ฐฉ๋ฌธ ์—ฌ๋ถ€ = true;
    if cost๊ฐ€ ์ €์žฅ๋œ max๋ณด๋‹ค ํฌ๋ฉด
        ๊ฐ€์žฅ ๋จผ ๋…ธ๋“œ ์ €์žฅ
        max = cost

    for ์—ฃ์ง€
        ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ๋…ธ๋“œ๋กœ dfs(์—ฃ์ง€.node, cost + ์—ฃ์ง€.cost) ํ˜ธ์ถœ
}

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

  1. ์–ด๋–ค ํ•œ ๋…ธ๋“œ๋กœ๋ถ€ํ„ฐ ๊ฐ€์žฅ ๋ฉ€๋ฆฌ์žˆ๋Š” ๋…ธ๋“œ๋Š” ํŠธ๋ฆฌ์˜ ์ง€๋ฆ„์˜ ์–‘ ๋์ค‘ ํ•˜๋‚˜์ด๋‹ค.
  2. ์—ฃ์ง€๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ์ €์žฅํ• ๋•Œ ์—ฃ์ง€๋ฅผ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•œ class๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์„œ ์ €์žฅํ•˜์ž.

Copy link
Member

@kjs254 kjs254 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
Collaborator

@rivkms rivkms left a comment

Choose a reason for hiding this comment

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

ํŠธ๋ฆฌ์˜ ์ง€๋ฆ„...
์ œ๊ฐ€ ์ด ๋ฌธ์ œ๋ฅผ PRํ•˜๊ธฐ ์œ„ํ•˜์—ฌ ํ’€๋‹ค๊ฐ€ ๊ฒฐ๊ตญ ํ•ด๋‚ด์ง€ ๋ชปํ•œ์ฑ„ ๋ฐฉ์น˜ํ–ˆ๋˜ ๊ธฐ์–ต์ด ์žˆ๋Š” ๋ฌธ์ œ์ธ๋ฐ, ํ’€์ด์— ์„ฑ๊ณตํ•˜์…จ๊ตฐ์š” ์ถ•ํ•˜๋“œ๋ฆฝ๋‹ˆ๋‹ค.
ํ’€์ด๋„ ์ •๋ง ์ž˜ ํ•ด์ฃผ์‹  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
์ € ๊ฐ™์€ ๊ฒฝ์šฐ์—๋Š” ๋ฉ”๋ชจ๋ฆฌ ์ดˆ๊ณผ๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ ์˜ค๋ฅ˜๋ฅผ ์ˆ˜์ •์ค‘์— ์žˆ๋Š”๋ฐ ๋ญ๊ฐ€ ๋ฌธ์  ์ง€ ์‚ฌ์‹ค ์ž˜ ๋ชจ๋ฅด๊ฒ ๊ตฐ์š”...

ํ’€์ด ์ƒ์—์„œ ํ•œ ๋…ธ๋“œ์—์„œ ์ œ์ผ ๋จผ ๋…ธ๋“œ๋ฅผ ์ฐพ๊ณ , ๊ทธ ๋…ธ๋“œ๋กœ๋ถ€ํ„ฐ ์ œ์ผ ๋จผ ๋…ธ๋“œ๋ฅผ ์ฐพ์•„ ํŠธ๋ฆฌ์˜ ์ง€๋ฆ„์„ ๊ตฌํ•œ ๋ฐฉ๋ฒ•์ด ๋˜๊ฒŒ ์ธ์ƒ๊นŠ์—ˆ๋˜ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ €๋„ ์ด ๋ฐฉ๋ฒ•์„ ์ฐธ๊ณ ํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ’€์ดํ•ด๋ด์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค. ์ข‹์€ ํ’€์ด์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค

์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค. ๐Ÿ˜

Copy link
Collaborator

@YIM2UL2ET YIM2UL2ET left a comment

Choose a reason for hiding this comment

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

๋จธ๋ฆฌ๋กœ๋Š” ์ดํ•ด๊ฐ€ ๋˜๋Š”๋ฐ ์–ด๋–ป๊ฒŒ ๊ตฌํ˜„์„ ํ•ด์•ผ ํ• ์ง€ ๋ง‰๋ง‰ํ•œ ๋ฌธ์ œ๋„ค์š”..
์ œ ์ˆ˜์ค€์—์„œ๋Š” ์•„์ง ์† ๋ธ ์ˆ˜ ์—†๋Š” ๋ฌธ์ œ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
๊ณต๋ถ€ ์ข€ ๋” ํ•˜๊ณ  ์™€์•ผ๊ฒ ๋„ค์š”.. ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค.

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.

4 participants