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 ...
随机推荐
- 【mysql-python】安装+基本使用
安装:从SourceForge.net上下载最新的MySQLdb,http://sourceforge.net/projects/mysql-python/ 运行exe文件 使用 From:http: ...
- Hibernate_day02--Hibernate的一级缓存
Hibernate的一级缓存 什么是缓存 1 数据存到数据库里面,数据库本身是文件系统,使用流方式操作文件效率不是很高. (1)把数据存到内存里面,不需要使用流方式,可以直接读取内存中数据 (2)把数 ...
- OpenSSL创建私有CA
1.编辑/etc/pki/tls/openssl.cnf [ CA_default ] dir = /etc/pki/CA # 工作目录certs ...
- std::condition_variable(二)
#include <iostream> // std::cout #include <thread> // std::thread, std::this_thread::yie ...
- C/C++ 智能指针简单剖析
导读 最近在补看<C++ Primer Plus>第六版,这的确是本好书,其中关于智能指针的章节解析的非常清晰,一解我以前的多处困惑.C++面试过程中,很多面试官都喜欢问智能指针相关的问题 ...
- 『SharePoint 2010』Sharepoint 2010 Form 身份认证的实现(基于AD)
一.进管理中心,创建一个应用程序,配置如下: 二.填端口号,和选择form身份认证,以及填写成员和角色,其他都默认就可以了 三.使用SharePoint 2010 Management Shell在里 ...
- ios 开发环境,证书和授权文件
一.成员介绍1. Certification(证书)证书是对电脑开发资格的认证,每个开发者帐号有一套,分为两种:1) Developer Certification(开发证书)安装在电脑上 ...
- nginx简单的nginx.conf配置
nginx.conf配置如下: #user nobody;worker_processes 1; #error_log logs/error.log;#error_log logs/error.log ...
- 深入HQL学习以及HQL和SQL的区别
HQL(Hibernate Query Language) 是面向对象的查询语言, 它和 SQL 查询语言有些相似. 在 Hibernate 提供的各种检索方式中, HQL 是使用最广的一种检索方式. ...
- SpringMVC的解释与搭建Maven私有代理服务器
SpringMVC静态资源处理 通常会配置SpringMVC拦截所有请求 即将DisptcherServlet的url-pattern设置为 / 此时会导致SpringMVC同时拦截.css .j ...