#P2207. [USACO13OPEN] Photo B
[USACO13OPEN] Photo B
Description
Farmer John plans to photograph his cows. They stand in a line and are numbered in order.
Each photo can include a contiguous interval of cows in the line. For every cow, FJ wants it to appear in at least one photo.
Unfortunately, there are pairs of cows that do not get along; they refuse to appear in the same photo. Given the positions of all incompatible pairs, compute the minimum number of photos FJ needs to take.
Input Format
The first line contains two integers .
Lines : on line , there are two integers and , indicating that the cow at position and the cow at position are an incompatible pair.
Output Format
Output a single integer, the minimum number of photos FJ needs.
7 3
1 3
2 4
5 6
3
Hint
Sample 1 explanation: FJ can take only three photos: .
Constraints: For of the testdata, it is guaranteed that , , .
Translated by ChatGPT 5
京公网安备 11011102002149号