d.一颗树,选最少的点覆盖所有边 s. 1.可以转成二分图的最小点覆盖来做.不过转换后要把匹配数除以2,这个待细看. 2.也可以用树形dp c.匈牙利算法(邻接表,用vector实现): /* 用STL中的vector建立邻接表实现匈牙利算法 效率比较高 处理点比较多的效率很高.1500的点都没有问题 */ #include<iostream> #include<stdio.h> #include<algorithm> #include<string.h>…
原题链接 此题求二分图的最小点覆盖,数值上等于该二分图的最大匹配.得知此结论可以将图染色,建有向图,然后跑匈牙利/网络流,如下.然而... #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int MAXN=2000+5; int q[MAXN],hd1[MAXN],hd2[MAXN]; int lnk[MAXN]; bool vis[MAXN],bw[MAX…
题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人间 最多能够有几组 思路:二分图判定+最大匹配 #include <cstdio> #include <cstring> #include <vector> using namespace std; const int maxn = 550; int vis[maxn];…
( ̄▽ ̄)" //凡无向图,求匹配时都要除以2 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<vector> using namespace std; ; int uN; vector<int> g[MAXN]; int link[MAXN]; bool vis[MAXN]; bool DFS(int u)…
二分图匹配模板题 #include <bits/stdc++.h> #define FOPI freopen("in.txt", "r", stdin); #define FOPO freopen("out.txt", "w", stdout); using namespace std; typedef long long LL; + ; int n, k, x, y; int link[maxn], vis[ma…
<题目链接> 题目大意:鲍勃喜欢玩电脑游戏,特别是战略游戏,但有时他无法找到解决方案,速度不够快,那么他很伤心.现在,他有以下的问题.他必须捍卫一个中世纪的城市,形成了树的道路.他把战士的最低数量的节点上,使他们可以观察所有的边.你能帮助他吗?士兵,鲍勃把一个给定的树,你的程序应该发现的最小数目. 解题分析: 最小点覆盖模板题,用最少的点来覆盖所有的边.建立无向图,然后求出其最大匹配,最小点覆盖数=最大匹配数.需要注意的是,本题用邻接矩阵存图跑匈牙利会T,所以用链式前向星存图. #includ…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054 题目大意:给你一棵树,选取树上最少的节点使得可以覆盖整棵树. 解题思路: 首先树肯定是二分图,因为树可以奇偶分层,从而根据二分图染色的原理可以确定树是二分图.我们可以用染色法确定出两个集合求最大匹配,也可以将边补成双向的,然后将最大匹配/2. 代码: #include<iostream> #include<cstdio> #include<cstring> #incl…
Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6586    Accepted Submission(s): 3066 Problem Description Bob enjoys playing computer games, especially strategic games, but some…
Problem Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieval city, the roads of which for…
Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2925    Accepted Submission(s): 1222 Problem Description Bob enjoys playing computer games, especially strategic games, but somet…