아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Strolling Cows

시간 제한1초메모리 제한1024 MB

요약
N개의 목초지 각각이 다른 목초지 하나로만 향하는 통로를 가질 때, 같은 목초지에서 시작하고 끝나며 다른 목초지를 두 번 방문하지 않는 가장 긴 산책의 길이를 구한다.
난이도

보통10점 중 5점

유형
그래프, DFS, 구현
정답자
아직 제출이 없습니다

문제

Before going to the barn for dinner, the cows like to stroll the N (1 ≤ N ≤ 30,000) pastures while watching the sun set. Each pasture leads to precisely one pasture, though some pastures have more than one pasture emptying into them. For a valid strolling experience, the cows can start in any pasture and must finish in that same pasture without visiting any other pasture twice. Given a description of the pasture paths, deduce the longest possible valid stroll the cows can take.

입력

  • Line 1: One integer: N
  • Lines 2..N+1: Line M tells the pasture number that pasture M-1 connects to (so line 2 tells which pasture is accessible from pasture 1, etc.)

출력

A single line with the integer that is the largest number of pastures that can be visited on a legal stroll.

예제1

  1. 예제 1

    입력
    5
    2
    4
    5
    5
    2
    
    예상 출력
    3