0% found this document useful (0 votes)
14 views4 pages

Role: Student: Name: Abhinav

Uploaded by

Abhinav Vats
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Role: Student: Name: Abhinav

Uploaded by

Abhinav Vats
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

eLab Role: Student Name: Abhinav Id: 307589233604 Dept: Computer Science And Engineering LOGOUT

November 11th 2024, 11:38:37 Pm

CHALLENGE INFORMATION

You have already solved this challenge ! Though you can run the code with different logic !

Course DS Session Tree 2 Question Information Level 1 Challenge 78

Problem Problem Description:

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

1 is the root node

Input format

First line: Two space-separated integers N and Q respectively


Second line: A string s of length N (where the i
th
character of s represents the character stored in node i)
Next N − 1 line: Two space-separated integers u and v denoting an edge between node u and node v

Next Q lines: An integer u and a space-separated character c


Output format
For each query, print the output in a new line.

Note: It is guaranteed that the input generates a valid tree.

Explanation for test case 1

Tree given in the sample input will look like that.

Number of nodes in the subtree of node 1 having 'a' stored in it is 2.

Test
Logical Test Cases
Cases

Test Case 1 Test Case 2

INPUT (STDIN) INPUT (STDIN)

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

Mandatory Test Cases

Complexity Test Cases

Test Case 1 Test Case 2 Test Case 3

CYCLOMATIC COMPLEXITY TOKEN COUNT NLOC

4 330 49

Code
You have already solved this challenge ! Though you can run the code with different logic !
Editor

Code Editor c Custom Input (stdin) T1 T2

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

Waiting for your Submission !


Your code will be Evaluated

For any inquiries, please contact your Faculty or Course Coordinator Student Manual DOWNLOAD

You might also like