Skip to content
DeepForgeby svx
All problems
MediumGraph Algorithmsgraph-247

WL Subtree Count

Problem

Count distinct Weisfeiler-Lehman colors after each refinement round, including round 0 before any refinement.

Each new color is the old color plus the sorted neighbor colors. labels is the initial color list, rounds is the number of refinements, and edges is a list of [u, v] pairs. Return the list of distinct color counts per round.

Hint

The number of distinct WL colors bounds how much structural information the test can see.

Test cases

case 1
in: [4,[[0,1],[1,2],[2,3]],[0,1,1,0],2]
expected: [2,2,2]
case 2
in: [3,[[0,1],[1,2],[2,0]],[0,0,0],2]
expected: [1,1,1]
case 3
in: [4,[[0,1],[0,2],[0,3]],[1,0,0,0],1]
expected: [2,2]
case 4
in: [2,[[0,1]],["a","b"],1]
expected: [2,2]
Starter codePython
def wl_subtree_count(n, edges, labels, rounds):
    # Your code here
    pass

4 test cases · run your code against them in the editor