회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
44%에서 왜 틀리는걸까요...
4195번 - 친구 네트워크
zebulun86
2년 전
0
반례를 다 찾아서 수정해도
틀렸다고나오네요
도대체 어떤 코너케이스가 들어가있길래
자꾸 틀리는걸까요
import sys input = sys.stdin.readline #4195번 친구 네트워크 parent = dict() connected = dict() #유니온 파인드 함수 def find(x): if parent[x] != x: return find(parent[x]) return x def union(x,y): unions = [find(x),find(y)] if unions[0] == unions[1]: print(connected[unions[0]]) return unions.sort() parent[unions[1]] = unions[0] if unions[0] not in connected: connected[unions[0]] = 2 else : if unions[1] in connected: connected[unions[0]] += connected[unions[1]] else : connected[unions[0]] += 1 print(connected[unions[0]]) def solve(): #친구 관계의 수만큼 입력 for _ in range(int(input())): p1, p2 = input().split() if p1 not in parent: parent[p1] = p1 if p2 not in parent: parent[p2] = p2 union(p1,p2) for _ in range(int(input())): solve() parent.clear() connected.clear()
댓글을 작성하려면
로그인
해야 합니다.
zebulun86 2년 전
반례를 다 찾아서 수정해도
틀렸다고나오네요
도대체 어떤 코너케이스가 들어가있길래
자꾸 틀리는걸까요