FForellin
제품

프로그램 기능 · 최소 신장 포리스트

01

spanning_forest.py에서 가장 싼 포리스트를 최단 경로나 임의 성분 분류와 구별하세요.

01

모델

기본 URL과 필요한 API 키로 OpenAI 호환 또는 Anthropic 엔드포인트를 설정하고 연결을 테스트하세요. 로컬 모델 서버는 실행 중이어야 합니다. 원격 도구는 데이터를 별도로 전송할 수 있습니다.

02

프로젝트

폴더를 선택하고 편집하기 전에 관련 파일을 읽도록 요청하세요. 작업의 목표와 변경 범위를 명확히 정합니다.

03

변경 사항

변경 사항과 명령 출력을 검토하세요. 결과를 채택하기 전에 프로젝트 검사를 실행해야 합니다. 생성된 코드는 자동으로 테스트된 코드가 아닙니다.

최소 신장 포리스트

● ● ●Forellin●
작업 흐름 · 최소 신장 포리스트 ×
def spanning_forest(count, edges):
    if type(count) is not int or not 0 <= count <= 64 or type(edges) is not list or len(edges) > 1024:
        raise ValueError("forest.input")
    ordered = []
    for edge in edges:
        if type(edge) not in (list, tuple) or len(edge) != 3 or any(type(x) is not int for x in edge):
            raise ValueError("forest.edge")
        a, b, weight = edge
        if not 0 <= a < count or not 0 <= b < count or abs(weight) > 10**9:
            raise ValueError("forest.bounds")
        ordered.append((weight, min(a, b), max(a, b)))
    parent = list(range(count))
    def root(node):
        while parent[node] != node:
            parent[node] = parent[parent[node]]
            node = parent[node]
        return node
    selected, total = [], 0
    for weight, a, b in sorted(ordered):
        x, y = root(a), root(b)
        if x != y:
            parent[x] = y
            selected.append((a, b, weight))
            total += weight
    return total, selected
✳최소 신장 포리스트
✓ 변경 사항적용하기 전에 검토하세요 ↗
작업 공간 예시 화면
AI 코딩 작업 공간

다음 아이디어가 여기서 시작됩니다.

Windows용 다운로드 ↗