-1
私はツリーを持っていて、各ノードに色付けしたいと思っていますblack or white
。ツリー着色有効であると言われている場合For every node N there exist at least One neighbor with the same color as of N
2色のツリーに彩色する
私のアプローチ:は
はDPを構築しましょう[2] 0,1は黒と白の
ways = (dp[0][i1]+dp[1][i1])*(dp[0][i2]+dp[1][i2)*.....i upto All Children of N
dp[0][N] = (ways-Number of ways when all the children are 1)
dp[1][N] = (ways-Number of ways when all the children are 0)
しかし、私のアプローチを表す[N]私に正解を与えていないのですか?私が逃しているものを手伝ってください。各ノードu
について
説明したステートメントでは、すべてのノードを同じ色で塗りつぶすだけで十分です。 –
これはModijiのプログラミングコンテストですか? –