Chef and Railway Network
The King of Treeland and Graphland have come together to help them out. Coming to the problem faced by the people in Treeland.
TreeLand needs to develop in it's railways networks. Chef and nuttela is figuring out solutions for making an improvement. The city has got $N$ stations and $N-1$ railway paths.
The stations are labelled from $1$ to $N$ only.
According to a survey, if $P$ passenger can travel everyday in a railway path, it is a "Good City".
TreeLand Junction is the root station and trains departs from this station to various directions. Every station is provided with a value $X$ , where $X$ denotes the number of passengers boarding trains.
Find the path from the junction station to end of the railway path (Last station of a particular path) which has the highest number of passengers travelling in that route(sum of total passengers in each station), let's call it $M$. If $M$ is greater than or equal to $P$, Treeland will be declared as a Good City .
Input:- First line will contain $T$, number of test cases.
- Second line contains, space-separated inputs, $N$ and $P$ -the number of stations in the city and the number of passengers.
- Every $N - 1$ lines follow, each with a pair of integers $u$ and $v$ denoting that there is an path between $u$ and $v$ station.
- The last line contains an array of integers storing $X$ ,the number of passengers in i-th station.
Output:- The Output "YES" or "NO". "YES" - if $M$ >= $P$ else "NO".
- $1 \leq T \leq 100$
- $1 \leq P \leq 1e9$
- $2 \leq N \leq1e4$
- $0 \leq X \leq 1e8$
1 2 5 7 3
ExplanationExample Case 1:
Check out the diagram to get a better understanding of the Railway flow. The green path is the chosen path. Since 7<=8, So "YES"
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions