#include <bits/stdc++.h>
using namespace std;
const int maxn = 301;
std::vector<int> son[maxn];
vector<int> G[maxn];
int deep[maxn], size[maxn];
vector<int> dep[maxn];
int vis[maxn];
int n, p, ans = 0x3f3f3f;
inline void dfs(int f) {
vector<int>::iterator it;
size[f] = 1;
for (it = son[f].begin(); it != son[f].end(); it++) {
int x = *it;
deep[x] = deep[f] + 1;
dfs(x);
size[f] += size[*it];
}
}
inline void hit(int root, int state) {
vector<int>::iterator it;
if (state == 1)
vis[root] = 1;
else
vis[root] = 0;
for (it = son[root].begin(); it != son[root].end(); it++) {
hit(*it, state);
}
}
inline void search(int d, int now) {
ans = min(ans, now);
vector<int>::iterator it;
for (it = dep[d].begin(); it != dep[d].end(); it++) {
if (!vis[*it]) {
hit(*it, 1);
search(d + 1, now - size[*it]);
hit(*it, 0);
}
}
}
int v[maxn];
inline void trans(int root) {
v[root] = 1;
vector<int>::iterator it;
for (it = G[root].begin(); it != G[root].end(); it++) {
if (!v[*it]) {
son[root].push_back(*it);
trans(*it);
}
}
}
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int main() {
// freopen("input.in", "r", stdin);
cin >> n >> p;
for (int i = 1; i <= p; i++) {
int x, y;
x = read();
y = read();
G[x].push_back(y);
G[y].push_back(x);
}
memset(v, 0, sizeof(v));
trans(1);
deep[1] = 0;
dfs(1);
for (int i = 1; i <= n; i++) {
dep[deep[i]].push_back(i);
}
search(1, n);
printf("%d\n", ans);
return 0;
}

P1041 传染病控制的更多相关文章

  1. P1041 传染病控制(dfs)

    P1041 传染病控制 题目背景 近来,一种新的传染病肆虐全球.蓬莱国也发现了零星感染者,为防止该病在蓬莱国大范围流行,该国政府决定不惜一切代价控制传染病的蔓延.不幸的是,由于人们尚未完全认识这种传染 ...

  2. 【搜索】P1041 传染病控制

    题目链接:P1041 传染病控制 题解: 这个题目是看别人的博客做出来的,其实挺不错的一个题目,考察的东西挺多的, 一个dfs可以处理5个东西: 1.找出父亲 2.找出深度 3.每一层的节点,存进Ve ...

  3. 洛谷 P1041 传染病控制

    P1041 传染病控制 题目背景 近来,一种新的传染病肆虐全球.蓬莱国也发现了零星感染者,为防止该病在蓬莱国大范围流行,该国政府决定不惜一切代价控制传染病的蔓延.不幸的是,由于人们尚未完全认识这种传染 ...

  4. P1041 传染病控制——暴力遍历所有相同深度的节点

    P1041 传染病控制 说实话这种暴力我还是头一次见,每次病毒都会往下传染一层: 数据范围小,我们可以直接枚举当前层保护谁就好了: 用vector 记录相同层数的节点:维护已经断了的点: 如果超出最底 ...

  5. [luogu]P1041 传染病控制[dfs]

    [luogu]P1041 传染病控制 ——!x^n+y^n=z^n 题目背景 近来,一种新的传染病肆虐全球.蓬莱国也发现了零星感染者,为防止该病在蓬莱国大范围流行,该国政府决定不惜一切代价控制传染病的 ...

  6. Luogu P1041 传染病控制(搜索)

    P1041 传染病控制 题意 题目背景 近来,一种新的传染病肆虐全球.蓬莱国也发现了零星感染者,为防止该病在蓬莱国大范围流行,该国政府决定不惜一切代价控制传染病的蔓延.不幸的是,由于人们尚未完全认识这 ...

  7. P1041 传染病控制【暴搜】

    P1041 传染病控制 提交 10.78k 通过 3.74k 时间限制 1.00s 内存限制 125.00MB 题目提供者CCF_NOI 难度提高+/省选- 历史分数100 提交记录 查看题解 标签 ...

  8. 洛谷P1041 传染病控制

    解:搜索...... 我们可以每次选择分支少的搜索,或者说,贪心的搜索当前更优的决策. 每一层把能剪的点搞出来,按照度数/SIZ排序,然后依次搜索.加个最优化剪枝就完事了. #include < ...

  9. luogu P1041 传染病控制

    题目背景 近来,一种新的传染病肆虐全球.蓬莱国也发现了零星感染者,为防止该病在蓬莱国大范围流行,该国政府决定不惜一切代价控制传染病的蔓延.不幸的是,由于人们尚未完全认识这种传染病,难以准确判别病毒携带 ...

随机推荐

  1. 使用curl进行https请求

    简单示例: /** * @param $url * @return array * 进行https请求,并且遇到location进行跳转 */ function https($url){ $resul ...

  2. 安装Yeoman,遇到的问题

    在安装Yeoman遇到了一些报错,具体的步骤就不多说了,直接上码,具体的两处报错的地方. 第一个,创建webapp,直接报权限的错误,这时才留意到在它之前还有一个错误. [root@iZ289zd8c ...

  3. iOS App禁止横屏

    修改Info.plist文件Supported interface orientations的项目 该项目是字典 把Landscape相关的键值删除即可

  4. js计算散点图方程式

    //pointArrayX,pointArrayY 为两个数组,分别为x轴对应的点和y轴对应的点 function getEquationPara(pointArrayX, pointArrayY) ...

  5. css中一些常用技巧

    // css中引入字体文件 @font-face { font-family: msyh; /*这里是说明调用来的字体名字*/ src: url('../font/wryh.ttf'); /*这里是字 ...

  6. LeetCode 219 Contains Duplicate II

    Problem: Given an array of integers and an integer k, find out whether there are two distinct indice ...

  7. Entity Framework 中的in操作实例

    var listimportDataEOIResoults = importDataEOIResoults.Select(i => i.ProductSelectionId).ToList(); ...

  8. 解决log4j:WARN No appenders could be found for logger

    这个问题是因为我们的log4j.properties文件配置不够完整,所以我们给它配置齐了就不会再出现这个问题. log4j.properties不完整配置如下: log4j.rootLogger=D ...

  9. Javascript获取select下拉框选中的的值

    现在有一id=test的下拉框,怎么拿到选中的那个值呢? 分别使用javascript原生的方法和jquery方法 <select id="test"  name=" ...

  10. 【转】B-树和B+树的应用:数据搜索和数据库索引

    B-树 1 .B-树定义 B-树是一种平衡的多路查找树,它在文件系统中很有用. 定义:一棵m 阶的B-树,或者为空树,或为满足下列特性的m 叉树: ⑴树中每个结点至多有m 棵子树: ⑵若根结点不是叶子 ...