CodeForces 687A NP-Hard Problem
Portal:http://codeforces.com/problemset/problem/687/A
二分图染色 好模板题 有SPJ
值得注意的是,因为C++的奇妙的运算机制
若在vector变量x.size()=0,则x.size()-1会溢出(此处坑了我3h)
这不禁让我想起了文明2里的甘地
#include<iostream>
#include<algorithm>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define LL long long
#define maxn 100010
#define SZ(x) int(x.size())
int n,m,j,x,y;
bool flag=true;
vector<int> a[maxn];
vector<int> ans[];
int col[maxn],len[maxn],vis[maxn];
bool dfs(int s,int color)
{
col[s]=color;
vis[s]=;
FOR(i,,SZ(a[s])-)
{
if(vis[a[s][i]]) {if(col[a[s][i]]==color) return false;}
else if(!dfs(a[s][i],-color)) return false;
}
if(color==) ans[].push_back(s); else ans[].push_back(s);
return true;
}
int main()
{
cin>>n>>m;
FOR(i,,m)
{
cin>>x>>y;
a[x].push_back(y);
a[y].push_back(x);
}
FOR(i,,n)
{
if(!vis[i]) if(!dfs(i,)) flag=false;
}
if(flag)
FOR(i,,)
{
cout<<SZ(ans[i])<<endl;
FOR(j,,SZ(ans[i])-) cout<<ans[i][j]<<' ';
cout<<endl;
}
else cout<<-<<endl;
return ;
}
神奇代码
神奇的(一劳永逸的?)做法
#define SZ(x) int(x.size())

嘿嘿嘿 define大法好
CodeForces 687A NP-Hard Problem的更多相关文章
- [codeforces 528]B. Clique Problem
[codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete ...
- codeforces.com/contest/325/problem/B
http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...
- Codeforces 442B Andrey and Problem(贪婪)
题目链接:Codeforces 442B Andrey and Problem 题目大意:Andrey有一个问题,想要朋友们为自己出一道题,如今他有n个朋友.每一个朋友想出题目的概率为pi,可是他能够 ...
- CodeForces 867B Save the problem
B. Save the problem! http://codeforces.com/contest/867/problem/B time limit per test 2 seconds memor ...
- Codeforces 776D The Door Problem
题目链接:http://codeforces.com/contest/776/problem/D 把每一个钥匙拆成两个点${x,x+m}$,分别表示选不选这把钥匙. 我们知道一扇门一定对应了两把钥匙. ...
- codeforces 803G Periodic RMQ Problem
codeforces 803G Periodic RMQ Problem 题意 长度为\(1e5\)的数组复制\(1e4\)次,对新的数组进行区间覆盖和区间最小值查询两种操作,操作次数\(1e5\). ...
- [Codeforces 986E] Prince's Problem
[题目链接] https://codeforces.com/contest/986/problem/E [算法] X到Y的路径积 , 可以转化为X到根的路径积乘Y到根的路径积 , 除以LCA到根的路径 ...
- 【codeforces 527D】Clique Problem
[题目链接]:http://codeforces.com/contest/527/problem/D [题意] 一维线段上有n个点 每个点有坐标和权值两个域分别为xi,wi; 任意一对点(i,j) 如 ...
- 【codeforces 793C】Mice problem
[题目链接]:http://codeforces.com/contest/793/problem/C [题意] 给你每个点x轴移动速度,y轴移动速度; 问你有没有某个时刻,所有的点都"严格& ...
- 【codeforces 807D】Dynamic Problem Scoring
[题目链接]:http://codeforces.com/contest/807/problem/D [题意] 给出n个人的比赛信息; 5道题 每道题,或是没被解决->用-1表示; 或者给出解题 ...
随机推荐
- CSS3实现一个旋转的花朵
要效果图如下: 实现原理:其实很简单,就是中间的圆圈定位在中间,其他的6个圆圈,进行不同的绝对定位,然后进行旋转!代码: <!DOCTYPE html> <html lang=&qu ...
- Oracle 11g rac开启归档
Oracle 11g rac开启归档 查看目前归档状态 #节点1 ykws1 SQL> archive log list; Database log mode No Archive Mode A ...
- Druid 0.17 入门(3)—— 数据接入指南
在快速开始中,我们演示了接入本地示例数据方式,但Druid其实支持非常丰富的数据接入方式.比如批处理数据的接入和实时流数据的接入.本文我们将介绍这几种数据接入方式. 文件数据接入:从文件中加载批处理数 ...
- mybatis探究之延迟加载和缓存
mybatis探究之延迟加载和缓存 一.什么是延迟加载 1.延迟加载的概念 在mybatis进行多表查询时,并非所有的查询都需要立即进行.例如在查询带有账户信息的用户信息时,我们们并不需要总是在加载用 ...
- Cinemachine中噪音的应用
两种默认产生噪音的方式 Nosie阶段的Component Component在流水线中主要通过MuteCameraState来处理对State的计算. 对于Noise类型的Component ...
- react / config\webpack.config.js 编译后去掉map 减小体积 shouldUseSourceMap = false
react / config\webpack.config.js 编译后去掉map 减小体积 shouldUseSourceMap = false
- npm install --save,npm install --save-dev,npm install
react npm install --save 与 npm install --save-dev 的区别以npm安装msbuild为例: nam install msbuild: 会把msbuild ...
- Css盒模型属性详解(margin和padding)
Css盒模型属性详解(margin和padding) 大家好,我是逆战班的一名学员,今天我来给大家分享一下关于盒模型的知识! 关于盒模型的属性详解及用法 盒模型基本属性有两个:padding和marg ...
- Linux常用命令 - wget命令详解(重点)
21篇测试必备的Linux常用命令,每天敲一篇,每次敲三遍,每月一循环,全都可记住!! https://www.cnblogs.com/poloyy/category/1672457.html 下载i ...
- Spring Cloud 系列之 Netflix Hystrix 服务容错
什么是 Hystrix Hystrix 源自 Netflix 团队于 2011 年开始研发.2012年 Hystrix 不断发展和成熟,Netflix 内部的许多团队都采用了它.如今,每天在 Netf ...