Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need a code in c !!! ASAP !!!!! John has got a tree with N vertices. The vertices are numbered from 1 to N.
I need a code in c !!! ASAP !!!!!
John has got a tree with N vertices. The vertices are numbered from 1 to N. He considers vertex 1 as the root of the tree. Each vertex of the tree contains a character C.
Now John is doing a weird experiment with this tree.
He often changes the character of a node in the tree and then sometimes he randomly selects a node v and tries to form a palindrome with all the characters in the subtree of node v.
But since John is very busy man and has a lot of other important experiments to do he needs your help on this one.
INPUT:
First line of the input contains an integer N (1<=N<=100000) denoting the number of vertices.
Next N-1 lines contains two integers A and B (1<=A, B<=N) which means there is an edge between vertex A and B.
Next line contains a string of length N. The ith character of this string denotes the character in node i.
Then there will be an integer M (1<=M<=100000) in a separate line denoting the number of queries. Next M lines will contain a query.
Each query will be in one of the following form:
0 x C: which means the character of node x has been changed to C.
1 x: which means you are asked to answer if a palindrome can be formed with all the characters in the sub tree of node x. There will be at least one query of this type.
OUTPUT:
For each query of the form 1 x print YES if a palindrome can be formed with all the characters in subtree of node x. Otherwise print NO (without the quotes).
(All the characters in the input will be small letters of English alphabet. i.e. a, b, c x, y, z).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started