题目链接

题意

给出一个无向图,要找出

  1. 数量大于 ⌈ K 2 ⌉ \lceil \frac{K}{2} \rceil ⌈2K​⌉ 的点独立集
  2. 长度不大于 K K K 的环

保证有一种解

题解

如果 m = n − 1 m=n-1 m=n−1(即为一棵树),那就之间二分图染色,两个独立集一定有一个大小 ≥ ⌈ K 2 ⌉ \ge \lceil \frac{K}{2} \rceil ≥⌈2K​⌉

否则图中一定有环,如果(环指的是简单环)

  1. 环大小小于等于K:直接输出环就好了

  2. 环大小大于K:那环里面隔一个输出一个,至少有 ⌈ K 2 ⌉ \lceil \frac{K}{2} \rceil ⌈2K​⌉ 个,而且都是相互独立的

#include<iostream>
#include<sstream>
#include<string>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<stack>
#include <utility>
#include<list>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<time.h>
#include<random>
using namespace std;
#include<ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#include<ext/rope>
using namespace __gnu_cxx;#define int long long
#define PI acos(-1.0)
#define eps 1e-9
#define lowbit(a) ((a)&-(a))
#define mid ((l+r)>>1)
#define mem(x,y) memset(x,y,sizeof x)const int mod = 1e9+7;
int qpow(int a,int b){int ans=1;while(b){if(b&1)ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;
}
const int INF = 0x3f3f3f3f;
const int N = 1e5+10;
int n,m,k,pre[N],dep[N],col[N],pos,mincir=INF;
vector<int>g[N],c[2];
void bfs(){mem(col,-1);queue<int>q; q.push(1); col[1]=1; c[1].push_back(1);while(!q.empty()){int u=q.front(); q.pop(); for(auto v:g[u]){if(col[v]==-1){col[v]=col[u]^1;q.push(v); c[col[v]].push_back(v);}}}
}
void dfs(int u,int fa){dep[u]=dep[fa]+1,pre[u]=fa;for(auto v:g[u]){if(v==fa)continue;if(dep[v]){if(dep[v]<dep[u]&&dep[u]-dep[v]+1<mincir){pos=u;mincir=dep[u]-dep[v]+1;}}else dfs(v,u);}
}
#define endl '\n'
signed main(){std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);cin>>n>>m>>k;for(int i=1;i<=m;i++){int u,v; cin>>u>>v;g[u].push_back(v),g[v].push_back(u);}if(m==n-1){bfs();cout<<1<<endl;if(c[0].size()>=(k+1)/2)for(int i=0;i<(k+1)/2;i++)cout<<c[0][i]<<" ";else for(int i=0;i<(k+1)/2;i++)cout<<c[1][i]<<" ";}else{dfs(1,1);if(mincir<=k){cout<<2<<endl<<mincir<<endl;while(mincir--){cout<<pos<<" ";pos=pre[pos];}}else{cout<<1<<endl;mincir=(k+1)>>1;while(mincir--){cout<<pos<<" ";pos=pre[pre[pos]];}}}
}

Codeforces Round #649 D. Ehab‘s Last Corollary 【思维,二分图,环】相关推荐

  1. [Codeforces Round #628]1325C - Ehab and Path-etic MEXs[思维][图]

    1325C - Ehab and Path-etic MEXs[思维][图] time limit per test memory limit per test input output 1 seco ...

  2. Codeforces round #628 C.Ehab and Path-etic MEXs

    Codeforces round #628 C.Ehab and Path-etic MEXs You are given a tree consisting of n nodes. You want ...

  3. 图论 ---- Codeforces Round #649 (Div. 2)D题[dfs求环+深度分层求图中独立集]

    D. Ehab's Last Corollary 题目大意: 就是给你一个联通图,你有两种选择 1.你可以输出包含⌈k2⌉\lceil{k\over2}\rceil⌈2k​⌉个顶点得独立点集,什么是独 ...

  4. Codeforces Round #742 (Div. 2) F. One-Four Overload 构造 + 二分图染色

    传送门 文章目录 题意: 思路: 题意: 给你一个n∗mn*mn∗m的矩形,包含...和XXX,你有两种颜色,你需要给...染色使得每个XXX上下左右相邻的...其两种颜色个数相同,输出一种合法方案. ...

  5. Codeforces Round #587 (Div. 3) C. White Sheet 思维

    传送门 文章目录 题意: 思路: 题意: 给你一个白色的矩形和俩个黑色的矩形,问白色被黑色覆盖后还能不能看到. 思路: 经典被简单题卡. 一开始写了个自我感觉很对的做法,结果wa41wa41wa41, ...

  6. Codeforces Round #636 (Div. 3) E. Weights Distributing 思维 + bfs

    传送门 文章目录 题意: 思路: 题意: n≤2e5,m≤2e5n\le2e5,m\le2e5n≤2e5,m≤2e5 思路: 怎么感觉每场div3div3div3都有一个巧妙的图论题. 首先如果只有两 ...

  7. Codeforces Round #617 (Div. 3) F. Berland Beauty 思维

    传送门 文章目录 题意: 思路: 题意: 给定一棵树,再给定若干两点最短路之间边权的最小值,让你给树的边权赋值,使得满足给定的条件,如果不存在输出−1-1−1. 思路: 观察一个性质,加入经过这条边的 ...

  8. Codeforces Round 649 (Rated for Div. 2)D. Ehab s Last Corollary详细题解(图论+简单环)

    树 边 : 树边: 树边:深度优先森林中的边.如果结点v是因对(u,v)的探索而首先被发现,则(u,v)是一条树边. 后 向 边 : 后向边: 后向边:后向边(u,v)是将结点u连接到其在深度优先树中 ...

  9. Codeforces Round #649 (Div. 2)C. Ehab and Prefix MEXs[排列的构造]

    C. Ehab and Prefix MEXs 题目大意: 解题思路:题目说保证a数组是非递减的,那么如果某位置a[i]!=a[i−1]a[i]!=a[i-1]a[i]!=a[i−1]那么这个位置ii ...

最新文章

  1. 为什么说Python是一门动态语言--Python的魅力
  2. Java中 VO、 PO、DO、DTO、 BO、 QO、DAO、POJO的概念
  3. 轻松删除git本地创建的仓库
  4. 对实体 useSSL 的引用必须以 ';' 分隔符结尾。
  5. python报错输出到日志_Python日志记录和子进程输出和错误流
  6. Python获取.wav音频的时长
  7. curl命令java_Java 应用线上问题排查思路、工具小结
  8. 【Python】 运算符
  9. CSS 普通流 和 行格式化上下文 IFC
  10. 申请计算机助理的英语作文,有关于应聘团队助理的申请信的英语作文要有中文翻译...
  11. 分支程序设计02 - 零基础入门学习C语言11
  12. Bitwise聘请前联邦检察官Katherine Dowling担任总法律顾问
  13. 艾伟也谈项目管理,学习腾讯的产品管理之道
  14. Solid angle to Arnold for Cinema4D破解教程
  15. python 多线程爬取网络小说
  16. win10声卡驱动问题:未检测到任何音频设备
  17. 单例模式、Single
  18. 一文扫尽检测类评估指标:AP、mAP、ReCall、OKS和IoU
  19. 2021.3.30-Robocup 2D学习日志
  20. vbs过程参数--byref和byval

热门文章

  1. Php session_start错误,PHP 解决错误:Warning: session_start()... 的方法
  2. String 判断纯数字 正则式
  3. Python基于机器学习的文本情感分析详细步骤[附代码和文字解释]
  4. sparkSql 随机打散分配
  5. 业务中台系统架构:大中台+小前台电子商务系统搭建框架思维
  6. 10分钟搞定Java带token验证的注册登录
  7. adb连接小米电视,尝试去除开机广告失败补救方法
  8. 公司用的非标普通自动化用单片机还是plc_自动化专业现在吃香吗?
  9. matlab处理时间数据绘图
  10. IDEA中Artifact的配置