Topology recognition and leader election are fundamental tasks in distributed computing in networks. The first of them requires each node to find a labeled isomorphic copy of the network, while the result of the second one consists in a single node adopting the label 1 (leader), with all other nodes adopting the label 0 and learning a path to the leader. We consider both these problems in networks whose nodes are equipped with not necessarily distinct labels called colors, and ports at each node of degree d are arbitrarily numbered 0,1,..., d - 1. Colored networks are generalizations both of labeled networks, in which nodes have distinct labels, and of anonymous networks, in which nodes do not have labels (all nodes have the same color). In colored networks, topology recognition and leader election are not always feasible. Hence we study two more general problems. Consider a colored network and an input I given to its nodes. The aim of the problem TOP, for this colored network and for I, is to solve topology recognition in this network, if this is possible under input I, and to have all nodes answer "unsolvable" otherwise. Likewise, the aim of the problem LE is to solve leader election in this network, if this is possible under input I, and to have all nodes answer "unsolvable" otherwise. We show that nodes of a network can solve problems TOP and LE, if they are given, as input I, an upper bound k on the number of nodes of a given color, called the size of this color. On the other hand we show that, if the nodes are given an input that does not bound the size of any color, then the answer to TOP and LE must be "unsolvable", even for the class of rings. Under the assumption that nodes are given an upper bound k on the size of a given color, we study the time of solving problems TOP and LE in the LOCAL model in which, during each round, each node can exchange arbitrary messages with all its neighbors and perform arbitrary local computations. We give an algorithm to solve each of these problems in arbitrary networks in time O(kD + D log(n/D)), where D is the diameter of the network and n is its size. We also show that this time is optimal, by exhibiting classes of networks in which every algorithm solving problems TOP or LE must use time Omega(kD + D log(n/D)). (C) 2016 Elsevier B.V. All rights reserved.