Alternating Colored Paths
All submissions for this problem are available.Given a tree of size N with each vertex colored either black or white. Find the number of paths with alternating colors.
First line will have N, the number of vertices of the tree and then N-1 lines will follow of the form u v which denotes an edge between the vertex u and v. Finally, the next line will contain the space separated color(either W for white or B for Black) of each vertex.
Single number denoting the number of paths with alternating colors modulo 10^9 + 7 (1000000007).
ConstraintsN <= 10^5
Input: 3 1 2 1 3 W B B Output: 6
ExplanationThese are the alternating colored paths ,,,[1,2],[1,3],[2,1,3]
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, 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, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.