Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
๐ ๋ฌธ์ ๋งํฌ
Miaximum Total Importance of Roads
โ๏ธ ์์๋ ์๊ฐ
1์๊ฐ
โจ ์๋ ์ฝ๋
์ฒซ ๋ฒ์งธ ํ์ด
๊ฐ ๋ ธ๋์ ์ฐ๊ฒฐ์ง์
roads
๋ฅผ ํตํด์ ๊ฐ ๋ ธ๋n
๊ฐ์ ํด๋นํ๋ 2์ฐจ์ ๋ฐฐ์ด์ ๋ง๋ค์ด์ค๋ค.๋ ธ๋์ ๊ฐ์๊ฐ ๋ง์ผ๋ฉด ๋์ ์ ์๋ฅผ ์ฐจ๋ก๋ก ๋ถ์ฌํ๋ค.
n
,n-1
,n-2
...0
์ด๋ฐ์์ผ๋ก..๊ทธ๋ฆฌ๊ณ ํด๋น ๊ฐ์ ์ ํฉ์
answer
์ ์ฐจ๊ทผ์ฐจ๊ทผ ์ ์ฅํด์ฃผ๋ฉด ๋๋๋ฐ๊ณ์ฐํ ๋ ธ๋๋ฅผ
unordered_map
์๋ค๊ฐ ๋ฃ์ด์ ๋ ๋ ธ๋๊ฐ ์ด๋ฏธ ๊ณ์ฐ๋ ๊ฐ์ด๋ผ๋ฉด ๊ณ์ฐ์ ์ํํ์ง ์๋ ์์ผ๋ก ์งํํ๋ ค๋ค๋ณด๋ ํ์ ๋ฉ๋ชจ๋ฆฌ์ ์ฝ๋๊ฐ ๋๋ฌด ์ง์ ๋ถํด์ก๋ค.์ฌ์ค ์ฐ๊ฒฐ๋ ๋ ธ๋๋ฅผ ๊ฐ๊ฐ ๋ฐ๋ก ๊ณ์ฐํ ํ์ ์์ด ์ฐ๊ฒฐ๋
degree
๋งํผ ๋ถ์ฌ๋ ์ ์๋ฅผ ์ฐ์ฐํด์ฃผ๋ฉด ๋๋ ๊ฒ์ด์๋ค.๋ ๋ฒ์งธ ํ์ด
์์์ ๋งํ๋๋ก ์ฐจ์์ ํด๋น ์ธ๋ฑ์ค๋ฅผ ์ฐ์ ์์ ํ๋ฅผ ํตํด ์ ๋ ฌ ์์ผ์ฃผ๊ณ ๋์ ์ฐจ์(
degree
)๋ฅผ ์ง๋ ๋ ธ๋๋ฅผ ํ๋์ฉ ๊บผ๋ด ์ ์๋ฅผ ๋งค๊ธฐ๊ณ degree๋งํผ ๊ณฑํด์ ๋ฐ๋ก ํด๊ฒฐํด์ฃผ๋ ์์ผ๋ก ๋ฐ๊พธ์๋ค.๊ฒฐ๊ณผ
ํ๊ธฐ
์์ ๊ฐ์ด ๊ตณ์ด ์ฐ์ ์์๋ฅผ ์ฌ์ฉํ ํ์๊ฐ ์๋ค. ์ผ๋ง๋ ์ฐ๊ฒฐ๋์ด์๋์ง ์ฐจ์๋ง ์๋ฉด ๋๊ธฐ ๋๋ฌธ!
๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ