[Luogu] 封锁阳光大学
2024-08-27 12:46:41
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 ;
}
最新文章
- MVVM大比拼之knockout.js源码精析
- java字符串相关
- CentOS 6.5 安装CodeBlocks
- visudo 使用摘记
- VelocityTracker简介
- Have You Ever Wondered About the Difference Between NOT NULL and DEFAULT?
- sql中实现split()功能
- C,C++容易被忽略的问题
- BootStrap2学习日记6---代码
- 使用WCF订阅替换轮训
- iOS打包app发给测试人员测试
- C# App.config配置文件的讲解
- JWPlayer支持SD/HD
- VIM基础知识整理(附思维导图)
- boost::pool 库速记
- temp-mootools简单语法
- JavaScript学习一之数据校验
- scrapy爬虫之模拟ajax post请求获取数据
- Linux(CentOS)下安装Elasticsearch5.0.0
- Python Web开发框架Django