Beruflich Dokumente
Kultur Dokumente
com/problems/TREEMX
Username Password Login New User
(https://www.codechef.com/certification/data-structures-and-algorithms/about?utm_source=website&utm_medium=adstrip&
Home (/) » Practice(Medium) (/problems/medium/) » Tree MEX
utm_campaign=jan20-adstrip)
All submissions for this problem are available.Minimum excludant (or All Submissions (/status/TREEMX)
MEX for short) of a collection of integers is the smallest non-negative
integer not present in the set.
Successful Submissions
ai = −1.
Set all
v1 , … , vn . For the current vertex vi
Process vertices in order set
ai = MEX(au1 , … , auk ), where u1 , … , uk is the set of
neighbours of vi .
For instance, letn = 3 and T be the tree with edges (1, 2) and (2, 3).
Then, for the ordering P = (1, 2, 3) we obtain the sequence
A(P ) = (0, 1, 0), while for the ordering P = (2, 3, 1) we obtain
A(P ) = (1, 0, 1).
Input:
The first line contains an integer T , denoting number of test cases.
The first line of each test case contains an integer n− the number of
5
vertices in the tree (1 ≤ n ≤ 10 ).
The following n − 1 lines describe the tree edges. Each of these lines
contains two integers ui , vi describing an edge between ui and vi
(1 ≤ ui , vi ≤ n, ui ≠ vi ).
Output:
Print the answer modulo 109 + 7.
Constraints
1 ≤ T ≤ 10
1 ≤ n ≤ 105
1 ≤ u i , vi ≤ n
u i ≠ vi
Sample Input:
1 of 3 07/12/18, 8:49 PM
We use cookies to improve your experience and for analytical purposes. Read our Privacy Policy (/privacy-policy) and Terms (/terms) to know more. You consent
Okay
to our cookies if you continue to use our website.
1
Tree MEX | CodeChef https://www.codechef.com/problems/TREEMX
5
1 2
2 3
3 4
4 5
Sample Output:
6
EXPLANATION:
For the sample case, the possible sequences A(P ) are (0, 1, 0, 1, 0),
(0, 1, 2, 0, 1), (0, 2, 1, 0, 1), (1, 0, 1, 0, 1), (1, 0, 1, 2, 0),
(1, 2, 0, 1, 0).
Date 17-11-2018
Added:
Languages: C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS
gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift,
D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS,
PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM,
LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin,
PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS
Comments
© 2009 Directi Group (http://directi.com). All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs (http://www.sphere-research.com)
In order to report copyright violations of any kind, send in an email to copyright@codechef.com (mailto:copyright@codechef.com)
(http://directi.com)
FAQ's (https://www.codechef.com/wiki/faq)
Initiatives
3 of 3 07/12/18, 8:49 PM
We use cookies to improve your experience and for analytical purposes. Read our Privacy Policy (/privacy-policy) and Terms (/terms) to know more. You consent
Okay
to our cookies if you continue to use our website.