This page is still under construction.

Parts of this page are still being built. What you see may change.

Milk Multidrink

Time limit1sMemory limit128 MB

Summary
Decide whether a tree with n nodes has a Hamiltonian path from 1 to n where consecutive vertices stay within distance two.
Level

Hard9 of 10

Topics
Tree, DFS, Greedy, Dynamic programming
Solved
No attempts yet

Problem

Byteasar lives in Byteburg, a city with a milk bar at every intersection. One day he came up with the idea of a milk multidrink: he wants to visit every milk bar in the city exactly once. He does not want to walk far after finishing a drink, so the next bar on his route has to be at most two blocks away from the intersection he is standing at. The distance between two intersections is the number of streets on the shortest route between them.

The intersections are numbered 11 through nn and every street is bidirectional. Between any two intersections there is exactly one route that never visits the same intersection twice. Byteasar starts at intersection 11 and finishes at intersection nn.

Decide whether an order of visits that meets his requirements exists.

In the city drawn above, visiting the bars in the order 1, 11, 8, 7, 5, 9, 2, 10, 4, 6, 3, 12 meets the requirements.

For the city drawn above no order meets the requirements.

Input

The first line contains one integer nn, the number of intersections in Byteburg (2≤n≤5000002 \le n \le 500000).

Each of the next n−1n-1 lines holds two distinct integers aia_i and bib_i separated by a single space (1≤ai,bi≤n1 \le a_i, b_i \le n). They describe the street that links intersections aia_i and bib_i.

Output

Print TAK on a single line if at least one order of visits meets Byteasar's requirements, and BRAK otherwise. TAK is Polish for yes and BRAK is Polish for none.

Examples2

  1. Example 1

    Input
    12
    1 7
    7 8
    7 11
    7 2
    2 4
    4 10
    2 5
    5 9
    2 6
    3 6
    3 12
    
    Expected output
    TAK
    
  2. Example 2

    Input
    15
    1 14
    14 7
    7 8
    7 11
    7 2
    2 4
    4 10
    2 5
    5 9
    2 6
    3 6
    3 15
    11 12
    8 13
    
    Expected output
    BRAK