This page is still under construction.

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

Escape

Time limit8sMemory limit128 MB

Summary
Decide whether detours on a tree can collect one-time HP gains so the hero walks from chamber 1 to chamber t without HP dropping below zero.
Level

Medium7 of 10

Topics
Graph, Greedy, Heap
Solved
No attempts yet

Problem

You hit the emperor lich with full force and slay it. There is a stair leading upwards here. You climb upstairs. You drink from the pool. You feel much better. The karmic lizard punches through your armor and hits you. You die...

After an epic fight with the emperor lich, the hero has to get out of a dungeon of nn chambers joined by n−1n - 1 corridors. He starts in chamber 11 and must reach chamber tt, moving only along corridors. Every chamber is reachable from chamber 11. Bruised from the last fight, the hero begins the journey with 00 hit points (HP). HP is his health: the moment it falls below zero, his story ends there as a tragic one.

Some chambers hold monsters. A monster must be fought, and the fight always takes some of the hero's HP. Other chambers hold magic pools, and every pool restores some HP. The hero's health has no upper limit. He can walk through a chamber as many times as he likes, but its gain or loss of HP happens only once, on the very first visit.

Determine whether the hero can escape the dungeon alive.

Input

The first line contains the number of test cases TT. The descriptions of the test cases follow.

The first line of each test case contains two integers: the number of chambers nn (2≤n≤200 0002 \le n \le 200\,000) and the number of the exit chamber tt (2≤t≤n2 \le t \le n). The second line contains nn space separated integers between −106-10^6 and 10610^6. The ii-th of them is the HP change in chamber ii: negative denotes a monster, positive denotes a pool, and zero means the chamber is empty. Chamber 11 does not hold a monster, but a pool is possible there. The exit chamber may hold a pool or a monster, and that monster has to be fought before escaping.

The next n−1n - 1 lines describe the corridors, one per line. Each line holds a pair of integers, the two chambers that the corridor connects.

Output

For each test case print a single line containing the word escaped if escape is possible, or trapped otherwise.

Examples1

  1. Example 1

    Input
    2
    7 7
    0 -3 2 2 3 -4 0
    1 2
    2 3
    2 4
    1 5
    5 6
    6 7
    3 2
    3 3 -4
    1 3
    2 3
    
    Expected output
    escaped
    trapped