Role: Student: Name: Abhinav
Role: Student: Name: Abhinav
CHALLENGE INFORMATION
You have already solved this challenge ! Though you can run the code with different logic !
You are given a rooted tree that contains N nodes. Each node contains a lowercase alphabet.
You are required to answer Q queries of type u, c , where u is an integer and c is a lowercase alphabet. The count of nodes in the subtree of the
node u containing c is considered as the answer of all the queries.
Constraints
5
1 ≤ N , Q ≤ 10
1 ≤ u, v ≤ N
c is a lowercase alphabet
si is a lowercase alphabet for all 1 ≤ i ≤ N
Input format
Test
Logical Test Cases
Cases
3 1 4 1
aba wsx
1 2 1 2
1 3 1 3
1 a 1 1
1 w
EXPECTED OUTPUT
2 EXPECTED OUTPUT
10
4 330 49
Code
You have already solved this challenge ! Though you can run the code with different logic !
Editor
1 #include<bits/stdc++.h>
Type Here
2
3 using namespace std;
4 //abhinav Vats RA2311003030310
5
6 void dfs(int node,int parent,string &s,vector<vect Output MATCH T1 MATCH T2
7 {
8 //visited[node]=1;
9 subroot[node][s[node-1]-'a']++;
10 //intime[node]=t;
Empty
11 //t++;
12 //z.push_back(node);
13 for( auto it:v1[node]) Complexity Analysis
14 {
15 if(it!=parent)
16 {
16 {
17 dfs(it,node,s,subroot,v1); Test Case Status
18 for(int i=0;i<26;i++)
19 subroot[node][i]+=subroot[it][i];
20 }
21 }
22 //outtime[node]=t;
23 //t++;
24 }
25 int main()
26 {
27 int N,i, Q;
28 string S;
SAVE RESET RUN EVALUATE
For any inquiries, please contact your Faculty or Course Coordinator Student Manual DOWNLOAD