https://www.luogu.org/problemnew/show/P1330

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector> using namespace std;
const int maxn = ;
int n, m;
vector<int> g[maxn];
bool vis[maxn];
int a[maxn],sum[]; bool dfs(int u, int col) {
vis[u] = true;
a[u] = col;
sum[col]++;
for (int i = ; i < g[u].size(); i++) {
int v = g[u][i];
if (vis[v] && a[v] == a[u])
return false;
else if (!vis[v]) {
if (!dfs(v, - col))
return false;
}
}
return true;
} int main() {
scanf("%d%d", &n, &m);
for (int i = ; i <= m; i++) {
int u, v;
scanf("%d%d", &u, &v);
g[u].push_back(v);
g[v].push_back(u);
}
int ans = ;
for (int i = ; i <= n; i++)
if (!vis[i]) {
sum[] = sum[] = ;
if (!dfs(i,)) {
printf("Impossible\n");
return ;
}
ans += min(sum[], sum[]);
}
printf("%d\n", ans); return ;
}

最新文章

  1. MVVM大比拼之knockout.js源码精析
  2. java字符串相关
  3. CentOS 6.5 安装CodeBlocks
  4. visudo 使用摘记
  5. VelocityTracker简介
  6. Have You Ever Wondered About the Difference Between NOT NULL and DEFAULT?
  7. sql中实现split()功能
  8. C,C++容易被忽略的问题
  9. BootStrap2学习日记6---代码
  10. 使用WCF订阅替换轮训
  11. iOS打包app发给测试人员测试
  12. C# App.config配置文件的讲解
  13. JWPlayer支持SD/HD
  14. VIM基础知识整理(附思维导图)
  15. boost::pool 库速记
  16. temp-mootools简单语法
  17. JavaScript学习一之数据校验
  18. scrapy爬虫之模拟ajax post请求获取数据
  19. Linux(CentOS)下安装Elasticsearch5.0.0
  20. Python Web开发框架Django

热门文章

  1. 使用babel es6 转 es5
  2. RMAN备份脚本执行遇到RMAN-03002,06091问题处理
  3. VMWare安装Ubuntu16.04
  4. SQL Server2008导入导出数据库
  5. elasticsearch 开机自启
  6. J.U.C之Condition
  7. 在浏览器输入URL回车后发生了什么?
  8. 判断上传文件是否为excel
  9. HTML5 使用localstorage 本地存储
  10. Json:Restful