Esempio n. 1
0
LL calc(int M) {
	memset(ok, false, sizeof ok);
	for (int j = 0; j < n; ++j)
		if (g[j].second <= M)
			ok[j] = true;
	LL ret = 0;
	mf.init();
	mf.s = n + m + 1;
	mf.t = n + m + 2;
	for (int j = 0; j < m; ++j) {
		bool flg = true;
		for (int k = 0; k < (int)f[j].size(); ++k)
			if (!ok[f[j][k]]) {
				flg = false;
				break;
			}
		if (flg) {
			ret += pro[j];
			mf.addEdge(mf.s, j, pro[j]);
			for (int k = 0; k < (int)f[j].size(); ++k)
				mf.addEdge(j, m + f[j][k], INF);
		}
	}
	for (int j = m; j < n + m; ++j)
		if (ok[j-m])
			mf.addEdge(j, mf.t, g[j-m].first);
	return ret - mf.maxFlow();
}
Esempio n. 2
0
void dfs(int u, MaxFlow& mf) {
	visited[u] = true;
	numbers.insert(u);
	vector<int> next = next_numbers(u);
	for(int v : next) {
		if(!visited[v])
			dfs(v,mf);
		mf.addEdge(u,v+L,1);
	}
}