Underground Lab

题解:

如果遍历一棵树,我们可以发现最多需要走的步数也不会超过2 * n步。

所以我们选出一棵树,然后遍历一边这颗树。

然后把序列分成k块就好了。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 2e5 + ;
int pre[N];
int Find(int x){
if(pre[x] == x) return x;
return pre[x] = Find(pre[x]);
}
vector<int> ans;
vector<int> c[N];
vector<int> vc[N];
void dfs(int o, int u){
ans.pb(u);
for(int v : vc[u]){
if(v == o) continue;
dfs(u, v);
ans.pb(u);
}
}
int Ac(){
int n, m, k, u, v;
scanf("%d%d%d", &n, &m, &k);
for(int i = ; i <= n; ++i) pre[i] = i;
for(int i = ; i <= m; ++i){
scanf("%d%d", &u, &v);
int fu = Find(u), fv = Find(v);
// cout << fu << " with " << fv << endl;
if(fu == fv) continue;
pre[fu] = fv;
vc[u].pb(v); vc[v].pb(u);
}
dfs(, );
// cout << "____" << endl;
int can = (*n + k-)/k;
for(int i = ; i < ans.size(); ++i){
c[i/can].pb(ans[i]);
}
for(int i = ; i < k; ++i){
if(c[i].size() == ) c[i].pb();
printf("%d", c[i].size());
for(int v : c[i]){
printf(" %d", v);
}
puts("");
}
return ;
} int main(){
Ac();
return ;
}

CodeForces 780 E Underground Lab的更多相关文章

  1. 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 ...

  2. codeforces781C Underground Lab

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  3. Codeforces 781C Underground Lab

    题目链接:http://codeforces.com/problemset/problem/781/C 因为有${K}$个机器人,每个又可以走${\left \lceil \frac{2n}{k} \ ...

  4. Codeforces 781C Underground Lab 构造

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF781C.html 题目传送门 - CF781C 题意 给定一个 n 个点 m 条边的无向连通图,请你用 k ...

  5. Underground Lab CodeForces - 782E (欧拉序)

    大意:$n$结点,$m$条边无向图, 有$k$个人, 每个人最多走$\left\lceil\frac {2n}{k}\right\rceil$步, 求一种方案使得$k$个人走遍所有的点 $n$结点树的 ...

  6. 782E. Underground Lab DFS 好题

    Link 题意:给出一个图,有n个点,m条边,k个人,每个人至多只能走$\lceil\frac{2n}{k}\rceil$步,输出可行的方案即输出每个人所走的步数和所走点 思路: 由于保证给出的是连通 ...

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

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

  8. 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 ...

  9. Codeforces Round#403 (Div. 1)

    唉,昨天晚上迷迷糊糊地去打cf,结果fst两题,掉回蓝了... A.Andryusha and Colored Balloons 题意:给定一棵树,任意两个距离小等于二的点不能染相同的颜色,求最小颜色 ...

随机推荐

  1. 【Android Studio】常用快捷键

    1. 删除一行:Ctrl + X 更新中……

  2. 【iOS】Updating local specs repositories

    使用 Pods 时遇到这个问题,原因是被墙了……需换成下面命令: pod install --verbose --no-repo-update

  3. MySQL多表(理论知识总结)

    1. 多表关系    外键    foreign key    添加外键语法:    alter table 表名1 add foreign key(外键名称) references 表名2(主键名称 ...

  4. gRPC的简单使用

    目录 前言 gRPC的简单介绍 基本用法 服务的定义 服务端代码编写 客户端代码编写 运行效果 服务治理(注册与发现) .NET Core 2.x 和 .NET Core 3.0的细微区别 扩展阅读 ...

  5. git常用指令整理

    git常用指令一览表 GIT指令 说明 git add . 将全部文件的内容加到Git索引以便执行commit. 这个指令不会检查文件夹中是否有文件被删除. 要注意的是,只有执行" git ...

  6. javascript数组去重 js数组去重

    数组去重的方法 一.利用ES6 Set去重(ES6中最常用) function unique (arr) { return Array.from(new Set(arr)) } var arr = [ ...

  7. Java——数据结构(链表)

    链表,可扩展长度,泛型. public class Link { Node header = null; //头结点 int length;//当前链表长度 class Node { Node nex ...

  8. tensorflow学习笔记——图像识别与卷积神经网络

    无论是之前学习的MNIST数据集还是Cifar数据集,相比真实环境下的图像识别问题,有两个最大的问题,一是现实生活中的图片分辨率要远高于32*32,而且图像的分辨率也不会是固定的.二是现实生活中的物体 ...

  9. if else 深度优化

    一. if else表达式过于复杂 if ((condition1 && condition2 ) || ((condition2 || condition3) && ...

  10. Vector使用方法简单整理

    使用vector,需要引用vector库: #include<vector> 首先,创建一个可以容纳int的vector变量——arr: vector<int> arr; 接着 ...