Crime
来源:互联网 发布:wto数据库 编辑:程序博客网 时间:2024/06/01 09:21
Crime
题意:给出n个点m条边,每条边有且只能选一个点,问最少选多少个点
.
.
题解:经典的黑白染色,dfs一次就可以了
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int maxn = 101000;const int maxm = 100100;int a[2*maxm], nextt[2*maxm], last[maxn], n, m, tot, t, sum;int f[maxn];bool flag;int min(int x, int y) { if (x<y) return x; return y;}void insert(int x, int y) { tot++; a[tot] = y; nextt[tot] = last[x]; last[x] = tot;}void dfs(int x) { sum++; if (f[x] == 1) t++; int k = last[x]; while (k != 0) { if (f[a[k]] == 0) { f[a[k]] = -f[x]; dfs(a[k]); } else if (f[a[k]] == f[x]) { flag = false; return; } if (!flag) return; k = nextt[k]; }}int main() { while (scanf("%d %d", &n, &m) != EOF) { memset(last, 0, sizeof(last)); memset(a, 0, sizeof(a)); memset(nextt, 0, sizeof(nextt)); memset(f, 0, sizeof(f)); tot = 0; flag = true; int x, y, ans = 0; for (int i = 1; i <= m; i++) { cin >> x >> y; insert(x, y); insert(y, x); } for (int i = 1; i <= n; i++) if (f[i] == 0) { sum = 0; t = 0; f[i] = 1; dfs(i); ans += min(sum-t, t); } if (!flag) { cout << "Impossible" << endl; } else cout << ans << endl; }}
0 0
- Crime
- A breach beyond CRIME
- Acdream 1729 Crime
- Kaggle 入门 Crime
- Crime and Punishment
- 1.4 Crime and Punishment
- Ural 1430. Crime and Punishment
- UVa10746 Crime Wave - The Sequel
- San Francisco Crime Classification(Kaggle)
- uva 10746 - Crime Wave - The Sequel
- 用 OData Service 访问 US Crime 数据
- UVA 10746 - Crime Wave - The Sequel
- UVA 10746 Crime Wave - The Sequel
- Ural 1430. Crime and Punishment(数论)
- Commit-and- Run Is a Crime
- uva 10746Crime Wave - The Sequel
- Crime Scene Investigation—都是指针惹的祸
- uva 10746 - Crime Wave - The Sequel(费用流)
- CentOS7:常用命令-笔记
- 2543. 【NOIP2011模拟9.1】直角三角形 (StandardIO)
- 1134 最长递增子序列
- map练习 统计参数个数
- CodeForce 675C 技巧题(其实我也不知道要归到什么里面去。。。)
- Crime
- Leetcode-pascals-triangle
- 数据结构之二叉树的建立与遍历
- 【1】【数学】CodeForces 588C Duff and Weight Lifting
- IplImage, CvMat, Mat 的关系
- 作用域注意事项
- 【项目】MFC下TCP/IP的套接字编程中CSocket,CSocketfile与CArchive类
- python 操作kafka
- leetcode-349. Intersection of Two Arrays