def encode_state(substate_node_set, state):
    """
    Injectively encode state and its substate (with respect to given
    subset of nodes) by (big) numbers.

    :param state: state to encode
    :param substate_node_set: nodes of the substate
    :return: (state code, substate code)
    """
    state_code = 0
    substate_code = 0
    for node, node_state in enumerate(state):
        if node_state:
            code_increase = 1 << node
            state_code += code_increase
            if node in substate_node_set:
                substate_code += code_increase
    return state_code, substate_code
