Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

c. What groups were least represented? Why do you think this is so?

Answered: 1 week ago

Question

b. What groups were most represented? Why do you think this is so?

Answered: 1 week ago

Question

3. Describe phases of minority identity development.

Answered: 1 week ago