codeforces781C Underground Lab
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。
本文作者:ljh2000
作者博客:http://www.cnblogs.com/ljh2000-jump/
转载请注明出处,侵权必究,保留最终解释权!
题目链接:codeforces781C Underground Lab
正解:生成树+欧拉序列
解题报告:
很容易发现,原图和图的一棵生成树其实是等价的,都是需要遍历全图,是一个类似于$dfs$的东西。
欧拉序列正可以满足题目所给的性质,所以我只要搞出一棵原图的生成树,然后把欧拉序列分成$k$段即可。
//It is made by ljh2000
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <complex>
using namespace std;
typedef long long LL;
typedef long double LB;
typedef complex<double> C;
const double pi = acos(-1);
const int MAXN = 200011;
const int MAXM = 400011;
int n,m,k,father[MAXN],ecnt,first[MAXN],next[MAXM],to[MAXM];
int dfn[MAXN*2],cnt,ans[MAXN],out;
inline int find(int x){ if(father[x]!=x) father[x]=find(father[x]); return father[x]; }
inline void link(int x,int y){ next[++ecnt]=first[x]; first[x]=ecnt; to[ecnt]=y; }
inline int getint(){
int w=0,q=0; char c=getchar(); while((c<'0'||c>'9') && c!='-') c=getchar();
if(c=='-') q=1,c=getchar(); while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return q?-w:w;
} inline void dfs(int x,int fa){
dfn[++cnt]=x;
for(int i=first[x];i;i=next[i]) {
int v=to[i]; if(v==fa) continue;
dfs(v,x);
dfn[++cnt]=x;
}
} inline void work(){
n=getint(); m=getint(); k=getint(); int x,y;
for(int i=1;i<=n;i++) father[i]=i;
for(int i=1;i<=m;i++) {
x=getint(); y=getint();
if(find(x)==find(y)) continue;
link(x,y); link(y,x);
father[find(x)]=find(y);
}
dfs(1,0); int now=0,cc,lim;
lim=2*n/k; if(lim*k<2*n) lim++;
for(int i=1;i<=k;i++) {
cc=0; out=0;
if(now<cnt) { while(cc<lim && now<cnt) now++,ans[++out]=dfn[now],cc++; }
else ans[out=1]=1;
printf("%d ",out);
for(int j=1;j<=out;j++) printf("%d ",ans[j]);
puts("");
}
} int main()
{
work();
return 0;
}
codeforces781C Underground Lab的更多相关文章
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E Underground Lab
地址:http://codeforces.com/contest/782/problem/E 题目: E. Underground Lab time limit per test 1 second m ...
- CodeForces 780 E Underground Lab
Underground Lab 题解: 如果遍历一棵树,我们可以发现最多需要走的步数也不会超过2 * n步. 所以我们选出一棵树,然后遍历一边这颗树. 然后把序列分成k块就好了. 代码: #inclu ...
- Codeforces 781C Underground Lab 构造
原文链接https://www.cnblogs.com/zhouzhendong/p/CF781C.html 题目传送门 - CF781C 题意 给定一个 n 个点 m 条边的无向连通图,请你用 k ...
- Codeforces 781C Underground Lab
题目链接:http://codeforces.com/problemset/problem/781/C 因为有${K}$个机器人,每个又可以走${\left \lceil \frac{2n}{k} \ ...
- Underground Lab CodeForces - 782E (欧拉序)
大意:$n$结点,$m$条边无向图, 有$k$个人, 每个人最多走$\left\lceil\frac {2n}{k}\right\rceil$步, 求一种方案使得$k$个人走遍所有的点 $n$结点树的 ...
- 782E. Underground Lab DFS 好题
Link 题意:给出一个图,有n个点,m条边,k个人,每个人至多只能走$\lceil\frac{2n}{k}\rceil$步,输出可行的方案即输出每个人所走的步数和所走点 思路: 由于保证给出的是连通 ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...
- Codeforces Round #403 (Div. 1, based on Technocup 2017 Finals)
Div1单场我从来就没上过分,这场又剧毒,半天才打出B,C挂了好几次最后还FST了,回紫了. AC:AB Rank:340 Rating:2204-71->2133 Div2.B.The Mee ...
- Codeforces Round#403 (Div. 1)
唉,昨天晚上迷迷糊糊地去打cf,结果fst两题,掉回蓝了... A.Andryusha and Colored Balloons 题意:给定一棵树,任意两个距离小等于二的点不能染相同的颜色,求最小颜色 ...
随机推荐
- Flask之请求和响应
from flask import Flask from flask import request from flask import render_template from flask impor ...
- python 字符串的格式化
python字符串的格式化分为两种:1)% 方式 2)str.format() 方式. str.format() 是比 % 较新的方式, 大多数的 Python 代码仍然使用 % 操作符.但最 ...
- 开启mysql的远程访问
1.登陆mysql数据库 mysql -u root -p 查看user表 mysql> use mysql;Database changedmysql> select host,user ...
- 怎么将linux下的项目转换成windows的VS2010下的项目?
怎么将linux下的项目转换成windows的VS2010下的项目? 不显示删除回复 显示所有回复 显示星级回复 ...
- TWebBrowser: Determine when a page with Frames is completed
TWebBrowser: Determine when a page with Frames is completed 6 comments. Current rating: (3 votes). L ...
- cocos2d-x 3.3 引用【#include "cocos-ext.h"】头文件出现编译错误
添加[#include "cocos-ext.h"] 头文件后报错 f:\projects\test_httpclient\cocos2d\extensions\gui\cccon ...
- .NET Core + EF 报nuget包不兼容
错误信息如下: 严重性 代码 说明 项目 文件 行 禁止显示状态错误 NU1107 Microsoft.EntityFrameworkCore 中检测到版本冲突.直接安装/引用 Microsoft.E ...
- python文件和目录操作方法
一.python中对文件.文件夹操作时经常用到的os模块和shutil模块常用方法.1.得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd()2.返回指定目录下的所有文件和目 ...
- asp.net Mvc 使用uploadify 上传文件 HTTP 302 Error
CSHTML代码 @{ if (Request.Cookies[FormsAuthentication.FormsCookieName] != null) { <input type=" ...
- 照着官网来安装openstack pike之neutron安装
neutron组件安装分为控制节点和计算节点,还是先从控制节点安装 1.前提条件,数据库为nova创建库和账户密码来连接数据库 # mysql -u root -p MariaDB [(none)]& ...