Skiers
Time limit1sMemory limit128 MB
Given a planar DAG whose edges leave clearings in west-to-east order, find the minimum number of downhill paths that cover every edge.
- Level
Hard8 of 10
- Topics
- Graph, Dynamic programming, Greedy, Implementation
- Solved
- No attempts yet
Problem
On the southern slope of a mountain there are several ski tracks and a single ski lift. Every track runs from the top station of the lift down to the bottom station. Each morning a team of lift workers inspects the tracks: they ride the lift up together to the top station, and then each worker skis down to the bottom station along a track of their own choosing. Every worker skis down exactly once. Different workers' routes may share sections. Every route always leads downwards.
The ski area is a network of clearings joined by cuttings through the forest. Every clearing sits at a distinct height, and any two clearings are joined by at most one cutting. Skiing from the top to the bottom, a worker can pass through any clearing (though not necessarily all of them in a single run). Routes meet only at clearings; there are no tunnels or bridges.
A cutting is inspected when at least one worker skis along it. The workers want to inspect every cutting between the clearings using as few workers as possible.
Write a program that reads the map of ski tracks and computes the minimum number of workers whose routes together cover every cutting.
Input
The first line contains one integer , the number of clearings (). The clearings are numbered from to : clearing is the top station of the lift and clearing is the bottom station.
Each of the next lines describes the downward cuttings leaving one clearing. Line (for from to ) describes clearing : it begins with an integer , the number of cuttings that lead down from clearing , followed by the numbers of the clearings they lead to, listed from west to east in the order the cuttings are arranged.
Output
Output a single integer: the minimum number of workers whose routes together inspect every cutting in the forest.