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

题目大意:

有n个节点,m条边,k个人,k个人中每个人都可以从任意起点开始走(2*n)/k步,且这个步数是向上取整的。要求:着k个人要走完所有的节点,且每个人至少走1步。

思路:= =dfs找一棵树,一棵树是n-1条边,所以从树根开始走完所有的,也就只有n*2-2步,所以不会达到上限。md这么简单都没有想到,233

//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
const int maxn = 2e5 + ;
int n, m, k;
vector<int> G[maxn];
bool vis[maxn];
vector<int> ans[maxn];
int lim, cnt, rest; void dfs(int u){
vis[u] = true;
ans[cnt].pb(u); rest--;
if (rest == ) {cnt++; rest = lim;}
for (int i = ; i < G[u].size(); i++){
int v = G[u][i];
if (vis[v]) continue;
dfs(v);
ans[cnt].pb(u); rest--;
if (rest == ) {cnt++; rest = lim;}
}
} int main(){
cin >> n >> m >> k;
for (int i = ; i <= m; i++){
int u, v; scanf("%d%d", &u, &v);
G[u].pb(v); G[v].pb(u);
}
lim = n * / k;
if (( * n) % k) lim++;
rest = lim, cnt = ;
dfs();
if (rest == lim) cnt--;
for (int i = cnt + ; i <= k; i++){
ans[i].pb(); ans[i].pb(G[][]);
}
for (int i = ; i <= k; i++){
printf("%d ", ans[i].size());
for (int j = ; j < ans[i].size(); j++){
printf("%d ", ans[i][j]);
}
cout << endl;
}
return ;
}

树的性质和dfs的性质 Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E的更多相关文章

  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)A模拟 B三分 C dfs D map

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

  3. 【贪心】【DFS】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C. Andryusha and Colored Balloons

    从任意点出发,贪心染色即可. #include<cstdio> #include<algorithm> using namespace std; int v[200010< ...

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

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

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

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

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

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

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

随机推荐

  1. Java:有关try、catch和finally的学习(供自己参考)

    Java:有关try.catch和finally的学习 在看到书本的时候对finally的介绍是:不论是否在try块中产生异常,都会执行finally.当时对这句话的理解不够深,误以为在try...c ...

  2. 基础算法学习2-dp

    一.算法题: 最大子阵 给定一个n×m 的矩阵 A,求A 中的一个非空子矩阵,使这个子矩阵中的元素和最大.其中,A 的子矩阵指在 A 中行和列均连续的一部分.输入格式输入的第一行包含两个整数 n,m( ...

  3. OSG学习:阴影代码示例

    效果图: 代码示例: #include <osgViewer/Viewer> #include <osg/Node> #include <osg/Geode> #i ...

  4. JavaScript设计模式学习之路——继承

    早在学习java的时候,就已经接触了继承,在java中因为有extends关键字,因此继承就比较简单.但是在JavaScript中,只能通过灵活的办法实现类的继承. 下面是我昨天在学习过程中,了解到的 ...

  5. 2nd 阅读构建之法有感

    阅读构建之法有感 利用这一周的时间,我大致了解构建之法一书,这本书带我走进了一个全新的领域.它让我以一种新的视角去了解软件产业的发展和工作,领略软件工程的独特魅力,更给出了简单易懂的方式去理解何为软件 ...

  6. 【final】评价①

    飞天小女警添加猜你喜欢功能,个人很喜欢.当推荐产品不喜欢的时候还有其他的选择,很人性化. 金州勇士将管理人员的角色分开,使整个系统的分工更明确,也更清晰. 新蜂的俄罗斯方块随着等级的提升有直观的颜色变 ...

  7. 【Linux 命令】- tail命令

    linux tail命令用途是依照要求将指定的文件的最后部分输出到标准设备,通常是终端,通俗讲来,就是把某个档案文件的最后几行显示到终端上,假设该档案有更新,tail会自己主动刷新,确保你看到最新的档 ...

  8. Android自定义XML属性以及遇到的命名空间的问题

    转载请注明出处:http://www.cnblogs.com/kross/p/3458068.html 最近在做一些UI,很蠢很蠢的重复写了很多代码,比如一个自定义的UI Tab,由一个ImageVi ...

  9. Golang的第一个程序-Hello, World !

    安装Golang: 1. 下载安装包 https://golang.google.cn/dl/ 我这里使用压缩包,下载后解压到D盘(自定义). 2. 添加环境变量:把解压后的bin目录添加到环境变量中 ...

  10. EVE-NG硬盘扩容,存储海量镜像

    EVE-NG硬盘扩容,存储海量镜像 来源 http://blog.51cto.com/sms1107/1928453 一.查看当前磁盘使用情况 /dev/mapper/eve--ng--vg-root ...