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的更多相关文章

  1. [codeforces 528]B. Clique Problem

    [codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete ...

  2. codeforces.com/contest/325/problem/B

    http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...

  3. Codeforces 442B Andrey and Problem(贪婪)

    题目链接:Codeforces 442B Andrey and Problem 题目大意:Andrey有一个问题,想要朋友们为自己出一道题,如今他有n个朋友.每一个朋友想出题目的概率为pi,可是他能够 ...

  4. CodeForces 867B Save the problem

    B. Save the problem! http://codeforces.com/contest/867/problem/B time limit per test 2 seconds memor ...

  5. Codeforces 776D The Door Problem

    题目链接:http://codeforces.com/contest/776/problem/D 把每一个钥匙拆成两个点${x,x+m}$,分别表示选不选这把钥匙. 我们知道一扇门一定对应了两把钥匙. ...

  6. codeforces 803G Periodic RMQ Problem

    codeforces 803G Periodic RMQ Problem 题意 长度为\(1e5\)的数组复制\(1e4\)次,对新的数组进行区间覆盖和区间最小值查询两种操作,操作次数\(1e5\). ...

  7. [Codeforces 986E] Prince's Problem

    [题目链接] https://codeforces.com/contest/986/problem/E [算法] X到Y的路径积 , 可以转化为X到根的路径积乘Y到根的路径积 , 除以LCA到根的路径 ...

  8. 【codeforces 527D】Clique Problem

    [题目链接]:http://codeforces.com/contest/527/problem/D [题意] 一维线段上有n个点 每个点有坐标和权值两个域分别为xi,wi; 任意一对点(i,j) 如 ...

  9. 【codeforces 793C】Mice problem

    [题目链接]:http://codeforces.com/contest/793/problem/C [题意] 给你每个点x轴移动速度,y轴移动速度; 问你有没有某个时刻,所有的点都"严格& ...

  10. 【codeforces 807D】Dynamic Problem Scoring

    [题目链接]:http://codeforces.com/contest/807/problem/D [题意] 给出n个人的比赛信息; 5道题 每道题,或是没被解决->用-1表示; 或者给出解题 ...

随机推荐

  1. docker 学习(四)

    1.Dockerfile简介 1)什么是Dockerfile Dockerfile是一个包含用于组合映像的命令的文本文档.可以使用在命令行中调用任何命令. Docker通过读取Dockerfile中的 ...

  2. 怎么用一行HTML代码搭建一个谷歌镜像?

    <iframe src="google.com"></iframe>

  3. java爬虫-妹子图

    一,分析 1.选择入口 ​ 打开 https://www.mzitu.com/ 主页,我们发现主页有200+页图片,我们如果从首页入手,这里可能不是全部图片.这里我们打开每日更新 https://ww ...

  4. url参数格式化

    getQueryBbj = (url)=>{ let urlData = url.split("?")[1]; let queryArr = urlData.split('& ...

  5. 大数据学习之scala-环境搭建

    scala 下载网站 https://www.scala-lang.org/download/ 安装scala要先安装java,并且配置java环境,官网也有说明 不过国内的网站下载不下来可以访问:  ...

  6. vlc 播放器的点播和广播服务

    vlc 是一个开源的,同时跨平台的播放器.在研究 rtsp 协议时发现,它同时还是一个强大的流媒体服务器 VLM VLM(VideoLAN Manager) 在 vlc 中是一个小型的媒体管理器,它能 ...

  7. Microsoft Visual Studio 修改语言包

    需求内容: 更改 Microsoft Visual Studio 界面的语言包(将中文改为英文) 解决方案: https://docs.microsoft.com/zh-cn/visualstudio ...

  8. C# MP3播放帮助类

    本文为原创文章如需转载请注明出处: /// <summary> /// ************************************************* /// 类名:M ...

  9. 五分钟了解Consul

    Hi,大家好,我叫consul,翻译成中文叫做“领事”,其实我更喜欢叫自己为中介,因为我觉得自己做的事情和房产中介非常像.比如说想要卖房的房东到我这边登记,我将房屋信息登录到我的表格中(服务注册),有 ...

  10. 【攻防世界】open-source

    难度系数: 3.0 题目来源: Pediy CTF 2018 题目描述:菜鸡发现Flag似乎并不一定是明文比较的 先用:PE查壳,发现没有