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表示; 或者给出解题 ...
随机推荐
- 【字节校招】【实习】【内推】字节跳动春招(校招或实习均可)以及日常实习内推ing
本人是年前刚刚入职抖音的应届生,职业认证还未来的级更改,但是这些都不重要.重要的是我们不能错过优秀的你~ 字节跳动的相关福利我就不介绍了,技术实习生是400/天,房补是1500/月,三餐免费,下午茶, ...
- 在Windows中像Linux里一样使用CMake和make
1. 安装GCC环境 1.1 安装MinGW(Minimalist GNU for Windows) 首先下载MinGW,并安装.安装完成之后运行MinGW Installer.界面如下.勾选自己需要 ...
- nodejs中的并发编程
从sleep的实现说起 在nodejs中,如果要实现sleep的功能主要是通过"setTimeout + promise"实现,也可以通过"循环空转"来解决.前 ...
- WPF 启动缓慢问题
Actually there's 2 main reasons that the default project type for WPF applications is x86. Intellitr ...
- BNP Paribas Cardif Claims Management
2月20日: 查看任务介绍,二分类问题,评价标准logloss 下载数据 2月21~27日: 查看数据组成,标识分类变量.离散变量.连续变量. 发现连续数据有大量非随机空缺(占总量一半),主要集中在v ...
- [AFO·游记]我的C++451天游击战
写在前面 05/10/19 今天心情很糟糕,没学新东西,复习没复习,作业没写完,下午要网课,明天要月考,脑子里就像是被一团棉花塞住了.静静的思考了半个小时,把自己手头上的事情排了个序,所以决定先把游记 ...
- LeetCode | 707. 设计链表
设计链表的实现.您可以选择使用单链表或双链表.单链表中的节点应该具有两个属性:val 和 next.val 是当前节点的值,next 是指向下一个节点的指针/引用.如果要使用双向链表,则还需要一个属性 ...
- Error: java.net.ConnectException: Call From tuge1/192.168.40.100 to tuge2:8032 failed on connection exception
先看解决方案,再看唠嗑,唠嗑可以忽略. 解决方案: 使用start yarn.sh启动yarn就可以了. 唠嗑: 今天学习Spark基于Yarn部署.然后总以为Yarn是让Spark启动的,提交程序的 ...
- 使用SpringBoot + JavaMailSender 发送邮件报错 Mail server connection failed;Could not connect to SMTP host
说明: 出于安全考虑,阿里云默认封禁 TCP 25 端口出方向的访问流量,无法在阿里云上的云服务器通过 TCP 25 端口连接外部地址. [官方提示]:如果您需要使用阿里云上的云服务器对外部发送邮件, ...
- 原创 记录一次线上Mysql慢查询问题排查过程
背景 前段时间收到运维反馈,线上Mysql数据库凌晨时候出现慢查询的报警,并把原始sql发了过来: --去除了业务含义的sql update test_user set a=1 where id=1; ...