We consider supervised learning problems where the features are embedded in a graph, such as gene expressions in a gene network. In this context, it is of much interest to automatically select a subgraph which has a small number of connected components, either to improve the prediction performance, or to obtain better interpretable results. Existing regularization or penalty functions for this purposetypicallyrequiresolvingamongallconnectedsubgraphsaselectionproblemwhichiscombinatoriallyhard. Inthispaper,weaddressthisissuefordirected acyclic graphs (DAGs) and propose structured sparsity penalties over paths on a DAG (called “path coding ” penalties). We design minimum cost flow formulations to compute the penalties and their proximal operator in polynomial time, allowing us in practice to efficiently select a subgraph with a small number of connected components. We present experiments on image and genomic data to illustratethesparsityandconnectivitybenefitsofpathcodingpenaltiesoversome existing ones aswell as the scalabilityof our approach forprediction tasks.