[BJOI 2018]染色
2024-10-21 06:40:43
题意:求01成立。
并查集维护,记录一个变量判断决策。
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 4000010;
int f[maxn];
inline int find(int x){
return x == f[x]?x : f[x] = find(f[x]);
}
signed main()
{
ios::sync_with_stdio(false);
int T;
cin >> T;
while(T--){
int n,m;
cin >> n >> m;
int tag = (m < n + 2);
for(int i = 1;i <= (n << 1); ++i){
f[i] = i;
}
for(int i = 1;i <= m; ++i){
int x,y;
cin >> x >> y;
f[find(x)] = find(y + n);
f[find(y)] = find(x + n);
}
for(int i = 1;i <= n && tag; ++i){
tag &= (find(i) != find(i + n));
}
if(tag) puts("YES");
else puts("NO");
}
return 0;
}
最新文章
- HTML2
- 博弈SG
- python中文编码
- magento app开发遇到的问题及解决
- C#中判断一个集合是另外一个集合的子集
- ADO.NET事务处理,初始回调函数,多张表的数据在同一个DataGridView中展示
- hdu1874 畅通工程续
- SQL 跨服务器数据库增、删、改、查(二)
- MySQL查询本周、上周、本月、上个月份数据的sql代码(转)
- CentOS_5.6下使用cmake编译MySQL_5.5.11
- k8s使用helm打包chart并上传到腾讯云TencentHub
- 【译】.NET 跨平台界面框架和为什么你首先要考虑再三
- chm提取
- linux下apache中httpd.conf的ServerAdmin 是设置的什么?
- Gitlab Runner的使用(涵盖gitlab-page)
- uva11383 转化为 二分图匹配
- FormValidator表单验证
- Pi 实现VLC网络视频监控
- json转List、Map
- django-settings.py配置