链接:https://www.nowcoder.com/acm/contest/180/C
来源:牛客网
题目描述:
小a的国家里有n个城市,其中第i和第i - 1个城市之间有无向道路连接,特殊的,第1个城市仅与第2个城市相连
为了减轻道路维护负担,城市规划局局长MXT给出了m个要求,他想让小a断开一些道路,使得任意1 ≤ i ≤ m ,城市xi不能到达城市yi
同时最小化断开道路的数量。
输入描述:
第一行两个整数n, m,分别表示城市的数量和请求的数量
接下来m行,每行两个整数x,y,表示需要使得x不能到达y
输出描述:
输出一个整数,表示最小断开桥的数量
思路: dp[j] = i ,表示(i,j)之间至少断开一条路 , 当有多条要求都指向j时,保留其中最大值。
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn= 1e6+ 5 ;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
char buf[(1 << 22)], *p1 = buf, *p2 = buf;
inline int read() {
char c = getchar(); int x =