Ad hoc user task composition involves automatic matching and selection of services across various devices in the pervasive environment. Existing service composition approaches mostly do not consider network heterogeneity or devices' capabilities simultaneously. This limits the composition mechanism, as not all the devices will be able to use the same set of network protocols. The user preferences are also not considered when selecting a particular service or device. In this paper, we propose a solution for ad hoc user task composition based on a graph-theoretic approach.We model both the user task and the underlying network services, along with their requirements and capabilities, as graphs. The heterogeneity of communication protocols is also considered in the graph. After an early elimination of unnecessary devices, and hence services, from the network services graph, based on user preferences and task requirements, a matching is performed between the user task graph and the simplified network services graph to achieve the composed user application.