Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E Underground Lab
地址:http://codeforces.com/contest/782/problem/E
题目:
1 second
256 megabytes
standard input
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.
The first line contains three integers n, m, 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.
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.
3 2 1
2 1
3 1
3 2 1 3
5 4 2
1 2
1 3
1 4
1 5
3 2 1 3
3 4 1 5
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的更多相关文章
- 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. 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 ...
- 树的性质和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步,且这个步数是向上取 ...
- 2-sat Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D
http://codeforces.com/contest/782/problem/D 题意: 每个队有两种队名,问有没有满足以下两个条件的命名方法: ①任意两个队的名字不相同. ②若某个队 A 选用 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- NPOI例子
例子链接:http://www.cnblogs.com/atao/tag/NPOI/default.html?page=1
- 实例讲解JQuery中this和$(this)区别
这篇文章主要介绍了实例讲解JQuery中this和$(this)的区别,this表示当前的上下文对象是一个html对象,可以调用html对象所拥有的属性和方法,$(this),代表的上下文对象是一个j ...
- ChemDraw中化学信息怎么通过Excel搜索
用户可以通过ChemDraw for Excel插件功能在Office Excel中建立ChemOffice菜单将ChemOffice和Excel结合使用,使用电子表格的最大优势之一就是可以清晰查看并 ...
- C++ 访问控制 public, protected, private, 友元
1. 变量属性与继承之间的关系 #include <iostream> using namespace std; class A { public: int x; protected: i ...
- IOS7 新特性(针对同样讨厌更新后IOS7的开发者)
本文转载至 http://blog.csdn.net/hanbing861210/article/details/13614211 您还未登录!|登录|注册|帮助 首页 业界 移动 云计算 研发 论坛 ...
- Linux内核态、用户态简介与IntelCPU特权级别--Ring0-3
一.现代操作系统的权限分离: 现代操作系统一般都至少分为内核态和用户态.一般应用程序通常运行于用户态,而当应用程序调用系统调用时候会执行内核代码,此时会处于内核态.一般的,应用程序是不能随便进入内核态 ...
- 【BZOJ5074】[Lydsy十月月赛]小B的数字 数学
[BZOJ5074][Lydsy十月月赛]小B的数字 题解:题目是问你ai*bi>=sum,bi>=0这个不等式组有没有解.因为a<=10,容易想到取ai的lcm,然后变成lcm*b ...
- Hibernate如何执行存储过程?
Hibernate如何执行存储过程? @Overridepublic Boolean setVarValue(final String processInstanceId, final String ...
- Delphi开发的服务在Windows2003 64位注册方式。
1.在sysWoW32目录下找到cmd.exe,右键运行方式选择administrator,输入密码后.2.TrainServer.exe -install 安装服务.
- Spoken English Practice(Don't get me wrong, that explanation makes no difference, I'm still mad at you. Come on, be reasonable!)
绿色:连读: 红色:略读: 蓝色:浊化: 橙色:弱读 下划线_为浊化 口语蜕变(2017/7/11) ...