A Tree Game

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

요약
모든 간선이 열린 트리에서 칩을 옮겨 차수가 1인 정점에 도달하려는 I와 매 라운드 간선 하나를 닫는 J의 승패를 판정한다.
난이도

보통10점 중 7점

유형
트리, 그리디, 게임 이론, DFS
정답자
아직 제출이 없습니다

문제

Little I and Little J are playing a game again.

Little J brings a tree with nn vertices. Each edge of the tree has two states: open and closed. Initially, all edges of the tree are open.

There is a chip initially placed at vertex 11. Little I can move the chip, and the goal is to move the chip to a vertex with degree exactly equal to 11. Little J can close edges of the tree with the goal of preventing Little I from moving the chip to a vertex with degree exactly 11. The degree of a vertex is the number of edges connected to it, regardless of whether they are open or closed.

The game consists of several rounds, each round having the following steps:

  1. Little I Task Determination: If the chip is at a vertex with degree exactly 11, Little I wins. Otherwise, proceed to step 2.
  2. Little J Action: Little J closes one currently open edge permanently. If there are no open edges at the moment, skip the action and proceed to step 3.
  3. Little I Action: Little I chooses an open edge connected to the vertex currently containing the chip, and moves the chip to the other end of this edge. If there is no such edge, Little J wins. Otherwise, a new round begins, going back to step 1.

Little J wants to know who will win if Little I and Little J know the structure of this tree and are extremely smart.

입력

The first line contains a single integer nn (1≤n≤1051 \le n \le 10^5) representing the number of vertices in the tree.

Then follow n−1n - 1 lines, each containing two integers uu and vv (1≤u,v≤n1 \le u, v \le n) representing two vertices connected by an edge of the tree.

출력

If Little I wins, print 1. Otherwise, print 0.

예제2

  1. 예제 1

    입력
    6
    1 2
    2 3
    2 4
    1 5
    5 6
    
    예상 출력
    0
    
  2. 예제 2

    입력
    7
    1 2
    2 3
    2 4
    1 5
    5 6
    5 7
    
    예상 출력
    1