Skip to content

week2/nonani#12

Open
nonani wants to merge 4 commits into
dandi-swm:mainfrom
nonani:main
Open

week2/nonani#12
nonani wants to merge 4 commits into
dandi-swm:mainfrom
nonani:main

Conversation

@nonani

@nonani nonani commented Jul 15, 2026

Copy link
Copy Markdown
Member

✏️ 2주차

해결한 문제

  • 멀리 뛰기
  • 섬 연결하기
  • 튜플

해결하지 못한 문제

  • 징검다리건너기
  • 괄호회전하기
  • 기지국설치

@nonani nonani changed the title week2/멀리뛰기/nonani week2/nonani Jul 15, 2026
@nonani nonani added the ✏️ 문제 풀었어요! 문제 풀이 PR에 부착되는 라벨입니다. label Jul 15, 2026
@nonani nonani self-assigned this Jul 15, 2026
@nonani
nonani marked this pull request as ready for review July 18, 2026 12:34
@Vryez11
Vryez11 requested review from Vryez11 and twalla26 July 19, 2026 02:44

@Vryez11 Vryez11 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

예비군 고생하셨습니다 ! 캬캬

int cost = nextNode[1];
if (visited[next])
continue;
pq.add(new int[]{next, cost});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

처음에 제가 느낀 생각은 graph로 초기화하는 것이 costs의 전체 길이라면 그냥,
costs[2]로 Arraysort() 한 다음에 그냥 간선의 개수가 n - 1 이 될 때까지 visited한게 더 좋지 않을까 ? 생각했었던 것 같습니다!

뭔가 임의의 시작점에서 정해진 목표로 가는데 이용하면 최적의 효율로 찾을 수 있겠다?라고 생각이 드는데 모든 점이 연결되어야 하는 문제 상황에서 graph로 초기화해야 하나? 라는 생각입니다 ㅋㅎㅋㅎㅋ

사실 제가 틀릴 수도 있어서 아래는 두 알고리즘을 비교한, AI 답변 첨부 드립니다.

1. 입력 형태와 맞아요. costs가 이미 간선 리스트라서 정렬만 하면 끝. 프림은 인접 리스트를 따로 만들어야
  해서 코드가 더 길어져요.
2. "연결되어 있는지 확인"이 곧 union-find예요. find(a) == find(b) 한 줄이 그 질문에 대한 답이라, 문제의
  핵심 동작과 자료구조가 정확히 일치해요. 프림은 연결 여부를 visited로 간접 관리하죠.
3. 간선이 적은 그래프에 유리해요. 이 문제는 섬 100개 이하의 희소 그래프라 크루스칼 O(E log E)가
  자연스러워요. 프림(인접행렬 O(V²) 버전)이 이기는 건 간선이 V²에 가까운 밀집 그래프일 때예요.

아.. 풀이 그건에 이미 알고 있었군요 죄송합니다 ......

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

싸이클 체크하는게 귀찮아서 크루스칼은 조금 꺼려지더라구요 ㅋㅋㅋ
이 문제는 입력 데이터 형식부터 크루스칼 쓰라고 의도한 문제가 맞는 것 같습니다 🤣

class Solution {
public int[] solution(String s) {

String[] subStrings = s.substring(2, s.length() - 2).split("\\},\\{");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 💯 !

@twalla26 twalla26 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! 👍

for (String number : sub.split(",")) {
int value = Integer.parseInt(number);

if (visited.add(value)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

set.add() 반환값이 boolean 이군요! 새로운거 알아갑니다 👍 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✏️ 문제 풀었어요! 문제 풀이 PR에 부착되는 라벨입니다.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants