给出一些点, 每个点有一个权值, 给出一些边, 起点以及终点, 去掉一些点使得起点和终点不连通, 求最小的val。
拆点, 把一个点s拆成s和s', 之间建一条边, 权值为点权。 对于一条边, <u, v> 建边<u, v'>, <v, u'> 权值为inf, 跑一遍最大流。
1 #include2 using namespace std; 3 #define pb(x) push_back(x) 4 #define ll long long 5 #define mk(x, y) make_pair(x, y) 6 #define lson l, m, rt<<1 7 #define mem(a) memset(a, 0, sizeof(a)) 8 #define rson m+1, r, rt<<1|1 9 #define mem1(a) memset(a, -1, sizeof(a)) 10 #define mem2(a) memset(a, 0x3f, sizeof(a)) 11 #define rep(i, a, n) for(int i = a; i pll; 14 const double PI = acos(-1.0); 15 const double eps = 1e-8; 16 const int mod = 1e9+7; 17 const int inf = 1061109567; 18 const int dir[][2] = { {-1, 0}, { 1, 0}, { 0, -1}, { 0, 1} }; 19 const int maxx = 405; 20 const int maxn = 40005; 21 int head[maxn*4], s, t, num, q[maxn*3], dis[maxn]; 22 struct node 23 { 24 int to, nextt, c; 25 }e[maxn*4]; 26 void init() { 27 mem1(head); 28 num = 0; 29 } 30 void add(int u, int v, int c) { 31 e[num].to = v; e[num].nextt = head[u]; e[num].c = c; head[u] = num++; 32 e[num].to = u; e[num].nextt = head[v]; e[num].c = 0; head[v] = num++; 33 } 34 int bfs() { 35 int u, v, st = 0, ed = 0; 36 mem(dis); 37 dis[s] = 1; 38 q[ed++] = s; 39 while(st 0) { 62 e[i].c -= tmp; 63 e[i^1].c += tmp; 64 cost += tmp; 65 if(cost == limit) 66 break; 67 } else { 68 dis[v] = -1; 69 } 70 } 71 } 72 return cost; 73 } 74 int dinic() { 75 int ans = 0; 76 while(bfs()) { 77 ans += dfs(s, inf); 78 } 79 return ans; 80 } 81 int main() 82 { 83 int n, m, val, x, y; 84 while(cin>>n>>m) { 85 cin>>s>>t; 86 t+=n; 87 init(); 88 for(int i = 1; i<=n; i++) { 89 scanf("%d", &val); 90 add(i, i+n, val); 91 } 92 while(m--) { 93 scanf("%d%d", &x, &y); 94 add(x+n, y, inf); 95 add(y+n, x, inf); 96 } 97 int ans = dinic(); 98 cout< <