Max. score.
20 00
Question 1 0
Black and white tree
from 1to N rooted at e
labeled
Given a tree with N vertices
graph with N-1edges Each edg
1. The tree is an undirected colaredeer
vertices, a, and b, Each vertex i is
Connects two
or black (represerted by T)
white (represented by 0)
the number of paths in its sutree t
The beauty of a vetex i is
of the opposite colot.
have end vertices
all N vertices.
Find the beauty of
Note subgraghconssting
a conicted
subtree of a vetex i is
" A includingL
descendantsofi
ofall the
Functiondescription follwing
takes the
This function
function solve.
Completethe
parameters:
vertices
numberof
Representsthe vertices
"N colorofthe sge
the
Represents denctng he
Color: elements
Represents the
Edges:
"Connectingtwovertices
testing cstam pul
custom agaist
formatfor testing bolerplane
Input youare provide
fomat if dont
input we
where
Use this language NetQuestt
Note:
a
o12Completed
Explanation
Given:
N=5
" Color ="1110
"Edges ([3. 1, (4, 3) (5, 3) 241
The glven tree is shown below
Approach:
(6-3-15-15-3-4$-1
simplepaths
"For vertex 1,there are 4
4-2). (5-35-3-45-3-4-2
simple paths
"For vertex 3, there are 3
there are no such simcie
"For vertices 2,4 and 5,
So, answer =(4,0,3,0, 0)
Note:
sample output tonte prov
Your code must be able to print the
sgainst mutoehicoenW
your code isrun te
sample [Link], passthesehiddentestcses
Therefore, your code must
problem statement.
Limite
(Previous Question
Hput formal for custom lesling
Note. Use his Input format tyou are
testing agairsl cutm ro
or wrilting code In a language where we dor't provde bolej
code.
he
" The first line contalns a singe rteger Ndercsq
number of verices in the tvee.
sting Colo sze h
The second line contains the
"
"0' andT.
consisting of characters Edges
describes elemerts of Edges
N 1 Iine eoçe
" The next denoting an undrected
integers a, and b,
containstwo numbereda,and b,
vertices
betweenthe
thebesuyd te
Outputformat denoting
integers
space-separated
Print N
vertices.
Constraints
1<N<10 Vie[1,N
1<a,b,
<NVie|1,N-1
1)
{0, Sample
output
Color,e
40380
Sample
input
Ne
OursoR
t
5
11110
31
43
53
C P r e v i oQ
uus estion
34
Cete the e
T eontes the folong 2 permetes and
long lis solve ( t , it , )
epreents the glven iteger value
Reresents the sze of atrey a
Reresets the value in the erray
Input format for custom testing
Note Use this input format if you are testing against
custominput or wrting code in a language where we
dont provide bolerplate code
The first line contains twontegers x and n.
The second line contains n integers
(aj,2.G)
Output format
Print an integerdenoting the value of the expression.
Constraints
1<n<10
1<z<n
0<a,sl0
Example Pinclude cstdio.h
Aesuimois Vint main(){
int num;
A12 34 5) scanf ("%d, Snum);
B2222.21 from
STOIN
printf(Input umber is Sd.\n, nun); Writing
M4
Anoroch
HK0then sum O
- K t take (2) as the chosen element from 8
then sum (2)22)-(32)-(42)(52) =3
-2-3-6- 7=21
fK2take 22) as the chosen elements from
8then sum = 2) (12) ((22)(212) J+ ((312)
-(32)-42) -(42] +(52) (52)) = (3 +2 +3
+6-72=42
Hence, K=2 is the minimum required to make
Sum 40
Function description
Complete the MinReg function provided in the editor.
This function takes the following 4 parameters and
returns the required answer
Max score: 50 00
1 ) #ineluitecSstdio.h
solve (Snt , int n, int s)
long long solv
Valie of an exression 11Typ your tode her
Gen eouence of ntegers l s e ) You
tollowing operation and
are esked to perform the
retum the detained resutt
For gven teger a, Calculste the value
of expression
Here. funa,,ae-1) eturns the value of
the rightmost number wth the highest number of
distinct prime factors
In other words, if m funla,G1yGyr-1). hen
you are reauired to find the value of min(m)
Function description
Compiete the solve function provided in the editor
This function takes the folloing 3 parameters and
returns the answer
Represents the given integer value
n Represents the size of array a
"a Represents the value in the array
Pevious Question Next Question View test casesA
Dtt orttat
tng evlue o the epression
Costralnts
Sample input Sample output
Explanation
m_t fune_1 e2 a_3) =6)
m_2 fune_2. e_3. 4) =10)
(m_3 funle_3. 4 6_5) = 10)
Value ot an expression
Guen&seauence of nintegers ( g You
e ked to peiform the following operation end
tetum the obtained resut
For egven integer , calculate the value
of expression
min fun(a,.d,leogG-1))
Here. funa,, uts ees@-t) returns the value of
the rightmost number with the highest number of
distinct prime factors
in other words, if m,= fun(a,, a,1,v**. Qjbz-1). then
you are required to find the value of min(m).
Function description
Complete the solve function provided in the editor.
This function takes the following 3 parameters and
returns the answer
"x Represents the given integer value
"n Represents the size of array a
"a Represents the value in the array
CPrevious Guestion Next Question >
tt r a t for custom testino 1)9ine ludecsstdio.h
(int , Snt n, int a) (
long long
Note Le s o a t if you are testing Bgainst S d e here
1iType your
where we
Cuto nout owiiting coce in a language 6 >)
oon't ooude toiierpiete coce
The ySt ne cotains two tegersKand n
-The seconc ine contsins nintegers
Output format
Print en meger denoting the value of the expression.
Constraints
1SESn
Sample input Sample output
1
inelude (stdio.h
etuoging- Minisum requtred valueJava V
int main()
Snt num;
The cocde editor gves you a code for the following Scanf("%, num);
from STDIN
protle statenment However. the solution faits the test
printf(Ingut nunber is Sd.\n. num) ; 1 Writing out
cases beceuse of code bugs Your task is to find and
7)
fx 8t the bugs S thst it passes all the test cases
Stateent
You are given two arrays, A and B. of size N consisting
of nonnegative ntegers
You have to select K numbers from B and take the
bitwse OR of allthe array elements in Awith the
chosen Knumbers and add their sum. In other words,
teke each elemet from array A and add
Its bitwise OR with eech chosen element from array B
to the sum (Note: You cannot choose two adjacent
elements in B)
Task
You have to find the minimum value of K
such that the
Sum is greater than or equel to M. Print-1 if
impossible
Example
Function description Finclud cstdio.h>
Cemplete the MRec tunctien povided in the edto V int main()
This Hunction tekes the foliowng 4 parameters and Snt num;
retuths the required ansver
scanf("d, inum);
from STOIN
6 printf("Input number is Sd.\n, num); 11witsng utput
N Represents the size of the arrey
7)
A Represents the first 8rray
-8 Represends the second aray from which we
heve to choose Kelements
"M Represents the lower lmit of the sum
Input format
Note This is the input format that you must use to
provide custom input (available above the Compile
and Test button)
" The first line coritains a single integer Twhich
denotes the number of test cases T also
denotes the number of times you have to run the
MinReq function ona different set of inputs
The Tcases are defined as follows
The first line of each case
contains N, denoting the size of the array.
The GACond line of eRch cASA
Contains N
Prevous Question
Fine lude stdio. ha
ow veue thet the mimm Afor ecn
of the ettnses Each vekie thet petnted ist be
1int main()
int num
scanf(S, Snum);
Constaints from STOIN
1 T 10 printf( Input umber is %d.\n num)
05A.B 10
Semple input Sample output
128
Explanation
For the first case, Na10 and