회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
NameError가 어디서 뜨는건지 모르겠습니다.
2644번 - 촌수계산
scudeto
2년 전
0
어떤 경우에 어떤 변수에서 NameError가 뜨는지 모르겠습니다 ㅠㅠ
import sys input = sys.stdin.readline n = int(input()) num1, num2 = map(int, input().split()) m = int(input()) dict = {} lst = [] for _ in range(m): parent, kid = map(int, input().split()) lst.append(parent) if parent in dict: dict[parent].append(kid) else: dict[parent] = [kid] lst = list(set(lst)) def Find_Num(root, height): global n1h, n2h, mom, num if root in lst: lst.remove(root) if root == num1 or root == num2 and num == 0: n1h = height mom = height -1 num = 1 elif root == num1 or root == num2 and num == 1: n2h = height print(n1h - mom + n2h - mom) exit() if root in dict: height += 1 for i in range(len(dict[root])): Find_Num(dict[root][i], height) else: return mom -= 1 while lst: num = 0 Find_Num(lst[0], 0) if num == 1: print(-1) break else: continue
댓글을 작성하려면
로그인
해야 합니다.
scudeto 2년 전
어떤 경우에 어떤 변수에서 NameError가 뜨는지 모르겠습니다 ㅠㅠ