As an emerging solution to latency requirements of Internet of Things (IoT) services, edge computing can bring powerful processing capacity closer to data sources. However, with the limited resources at edge nodes, a major challenge is finding optimal resources in distributed edges to reduce the operational costs of service deployment. Prior works focus mainly on static optimization which may not work efficiently with the time-varying workloads and resource constraints. In this paper, we, therefore, consider an optimization allocation framework in the edge-cloud network with time-varying workloads. In such a system, we introduce a joint routing and placement problem for IoT services, called the JORP, that dynamically assigns resources according to workload demand in order to reduce the operational costs. Inspired from the well-known algorithm, branch-and-bound (BnB), for solving the mixed-integer nonlinear problems (MINLPs) like JORP, we bring the learning concept to address the high complexity of BnB when the search space is huge. Particularly, we design a deep neural network (DNN) and train it under the imitation learning to mimic branching behaviors in BnB for searching the optimal solution.