ch6092 hide and seek (DAG minimum coverage points repeatable path)

Ideas:

Why this topic is the smallest positive solution path DAG repeatable point cover it? ? ? Bloggers depressed for two days (actually playing the game for two days) , get the answer suddenly from the game (actually playing the game dishes, abused, or encountered anchor ,,, autistic, and will come to learn child)

Small BB, text from this moment. 


First clear, solving one of the biggest set of points, did not meet the set path of points between any two points. ohhhh? ? ? This is not the maximum independent set it? ? ? Unfortunately, this is a directed graph, the largest independent set is for free, and if you go to define a bipartite graph, you will find the map, the front has a premise, a undirected graph how how, that is a bipartite graph in terms of undirected graph. That can not have this as the largest independent set to consider a plan.

But we have to know waypoint FIG minimum coverage, defined as follows: select at least disjoint edge covering all vertices . Minimum path covered can be repeated: select at least cover all the edges may intersect the vertices . For this set of paths, each picked out from the inside up to a point, if you pick out more than one point, for example two, then certainly there is a simple path may be a connection between these two points, that is certainly both one party can reach the other side. So from all of our paths, each path pick a point, finally make up the largest collection point.

There is little need to explain why this issue is covered by a minimum path can be repeated, because the subject has said that if a point of walking along a path to reach another point, the two points also could see of each other , that is to say for the side a-> b, b-> c, indirect a-> c can be considered. Therefore, on the first request at floyd transitive closure split point to establish a bipartite graph, DAG and then run again covered a minimum path point. (Such problems are more accustomed to bloggers adjacency matrix directly QAQ)

 

/**
 *
 * Author: correct
 *
 */
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof a)
using namespace std;
const int N = 210;
bool w[N][N];
int match[N];
bool vis[N];
int n, m;
bool dfs(int x){
	for (int i = 1; i <= n; i++){
		if (w[x][i] && !vis[i]){
			vis[i] = 1;
			if (match[i] == -1 || dfs(match[i])){
				match[i] = x;
				return 1;
			}
		}
	}
	return 0;
}
void pre_work(){
	mem(match, -1);
	mem(vis, 0);
	for (int k = 1; k <= n; k++){
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				w[i][j] = (w[i][k] && w[k][j]) || w[i][j];
			}
		}
	}
}
int solve(){
	int ans = n;
	for (int i = 1; i <= n; i++){
		mem(vis, 0);
		if (dfs(i))ans--;
	}
	return ans;
}
int main()
{
	mem(w, 0);
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= m; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		w[x][y] = 1;
	}
	pre_work();
	printf("%d\n", solve());
	return 0;
}

 

Published 204 original articles · won praise 13 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_43701790/article/details/104731791