地址:http://codeforces.com/contest/782/problem/E

题目:

E. Underground Lab
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The evil Bumbershoot corporation produces clones for gruesome experiments in a vast underground lab. On one occasion, the corp cloned a boy Andryusha who was smarter than his comrades. Immediately Andryusha understood that something fishy was going on there. He rallied fellow clones to go on a feud against the evil corp, and they set out to find an exit from the lab. The corp had to reduce to destroy the lab complex.

The lab can be pictured as a connected graph with n vertices and m edges. k clones of Andryusha start looking for an exit in some of the vertices. Each clone can traverse any edge once per second. Any number of clones are allowed to be at any vertex simultaneously. Each clone is allowed to stop looking at any time moment, but he must look at his starting vertex at least. The exit can be located at any vertex of the lab, hence each vertex must be visited by at least one clone.

Each clone can visit at most  vertices before the lab explodes.

Your task is to choose starting vertices and searching routes for the clones. Each route can have at most  vertices.

Input

The first line contains three integers nm, and k (1 ≤ n ≤ 2·105, n - 1 ≤ m ≤ 2·105, 1 ≤ k ≤ n) — the number of vertices and edges in the lab, and the number of clones.

Each of the next m lines contains two integers xi and yi (1 ≤ xi, yi ≤ n) — indices of vertices connected by the respective edge. The graph is allowed to have self-loops and multiple edges.

The graph is guaranteed to be connected.

Output

You should print k lines. i-th of these lines must start with an integer ci () — the number of vertices visited by i-th clone, followed by ci integers — indices of vertices visited by this clone in the order of visiting. You have to print each vertex every time it is visited, regardless if it was visited earlier or not.

It is guaranteed that a valid answer exists.

Examples
input
3 2 1
2 1
3 1
output
3 2 1 3
input
5 4 2
1 2
1 3
1 4
1 5
output
3 2 1 3
3 4 1 5
Note

In the first sample case there is only one clone who may visit vertices in order (2, 1, 3), which fits the constraint of 6 vertices per clone.

In the second sample case the two clones can visited vertices in order (2, 1, 3) and (4, 1, 5), which fits the constraint of 5 vertices per clone.

思路:dfs一遍,记录路径(路径上点的个数最多2*N),然后将所有路径分配给k个克隆人。

#include <bits/stdc++.h>

using namespace std;

#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=4e5+;
const int mod=1e9+; int n,m,num,k,cnt,vis[K],rk[K];
vector<int>mp[K]; void dfs(int x)
{
vis[x]=,rk[++cnt]=x;
for(int i=;i<mp[x].size();i++)
if(!vis[mp[x][i]])
dfs(mp[x][i]),rk[++cnt]=x; } int main(void)
{
cin>>n>>m>>num;
for(int i=,x,y;i<=m;i++)
scanf("%d%d",&x,&y),mp[x].PB(y),mp[y].PB(x);
k=(*n+num-)/num;
dfs();
for(int i=,sum;i<=num;i++)
{
sum=min(k,cnt);
if(sum==)
{
printf("1 1\n"); }
else
{
printf("%d ",sum);
for(int j=;j<=sum&&cnt;j++,cnt--)
printf("%d ",rk[cnt]);
puts("");
}
}
return ;
}

Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E Underground Lab的更多相关文章

  1. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)

    Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...

  2. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League

    地址:http://codeforces.com/contest/782/problem/D 题目: D. Innokenty and a Football League time limit per ...

  3. 树的性质和dfs的性质 Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E

    http://codeforces.com/contest/782/problem/E 题目大意: 有n个节点,m条边,k个人,k个人中每个人都可以从任意起点开始走(2*n)/k步,且这个步数是向上取 ...

  4. 2-sat Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D

    http://codeforces.com/contest/782/problem/D 题意: 每个队有两种队名,问有没有满足以下两个条件的命名方法: ①任意两个队的名字不相同. ②若某个队 A 选用 ...

  5. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C Andryusha and Colored Balloons

    地址:http://codeforces.com/contest/782/problem/C 题目: C. Andryusha and Colored Balloons time limit per ...

  6. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed

    地址:http://codeforces.com/contest/782/problem/B 题目: B. The Meeting Place Cannot Be Changed time limit ...

  7. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) A. Andryusha and Socks

    地址:http://codeforces.com/contest/782/problem/A 题目: A. Andryusha and Socks time limit per test 2 seco ...

  8. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)A模拟 B三分 C dfs D map

    A. Andryusha and Socks time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  9. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals )D. Innokenty and a Football League(2-sat)

    D. Innokenty and a Football League time limit per test 2 seconds memory limit per test 256 megabytes ...

随机推荐

  1. Struts2_day02--Struts2封装获取表单数据方式

    Struts2封装获取表单数据方式 原始方式获取表单封装到实体类对象 属性封装(会用) 1 直接把表单提交属性封装到action的属性里面 2 实现步骤 (1)在action成员变量位置定义变量 - ...

  2. UE4插件

    源代码中包含一些插件例子 C:\Program Files\Epic Games\UE_4.15\Engine\Plugins\Developer 一下截图来自官网https://docs.unrea ...

  3. flask模块

    import flask, json #把当前的文件当成一个服务 server = flask.Flask(__name__) @server.route('/index', methods=['ge ...

  4. jQuery源码分析-each函数

    本文部分截取自且行且思 jQuery.each方法用于遍历一个数组或对象,并对当前遍历的元素进行处理,在jQuery使用的频率非常大,下面就这个函数做了详细讲解: 复制代码代码 /*! * jQuer ...

  5. linux安装yaf(ubuntu教程)

    $PHP_BIN/phpize 这个是什么 其实这个是一个扩展 apt-get install php5-dev 这样电脑会帮你自己配置了,很简单的下面我们就下载扩展包了http://pecl.php ...

  6. 将工程导入到SVN仓库

    1.在桌面右键点开Tortoise客户端 2.选择仓库 3.在仓库的trunk目录下为新工程创建文件夹

  7. GNU Libtool

    Fastbit (WAH)的代码可在链接中下载 安装以及运行命令如下: 解压命令: $ tar -zxvf fastbit-ibis1.3.8.tar.gz 安装命令: $ cd fastbit-ib ...

  8. INFORMATION_SCHEMA.STATISTICS 统计 表 库 大小

    INFORMATION_SCHEMA MySQL :: MySQL 5.5 Reference Manual :: 21 INFORMATION_SCHEMA Tables https://dev.m ...

  9. scrapy - grab english name

    wxpath定位-采集验证-入库-使用. from scrapy.spider import Spider from scrapy.crawler import CrawlerProcess clas ...

  10. oracle 归档空间满的解决办法

    问题现象: 通过命令提示符登陆数据库,一般提示“ora-03113:通信通道的文件结尾”错误,查看trace日志,可以看到详细信息.部分摘录如下(橙色部分给出了建议方案): Errors in fil ...