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 ;
}

最新文章

  1. OC笔记一:Objective-C简介
  2. 【WEB API项目实战干货系列】- API登录与身份验证(三)
  3. Java web项目的字符集问题
  4. 从本地上传整个目录到hdfs的java程序
  5. WPF Mahapps.Metro 设置主题样式
  6. 什么是Elasticsearch
  7. http缓存协议详解
  8. jQuery动画方法
  9. 微信小程序支付+php后端
  10. RestTemplate的使用
  11. E2040 Declaration terminated incorrectly - System.ZLib.hpp(310) ZLIB_VERSION
  12. 代码生成器 CodeSmith 的使用(三)
  13. EF简易教程,从建表到表间关系
  14. linux下mysql自动备份脚本
  15. Intellij idea的Dependencies波浪线
  16. Session应用之验证码
  17. LintCode2016年8月8日算法比赛----子树
  18. HDU 2897 邂逅明下 ( bash 博弈变形
  19. hdu1422重温世界杯(动态规划,最长子序列)
  20. Django--ORM基础

热门文章

  1. git中的重要指令
  2. c# 窗体与窗体外的文件互动(拖拽)
  3. KNN算法之图像处理二
  4. FPGA的软核与硬核
  5. .NET Core使用EF分页查询数据报错:OFFSET语法错误问题
  6. keepalived 高可用(IP飘移)
  7. (转) Elasticsearch 5.0 安装 Search Guard 5 插件
  8. TDDL实践
  9. BZOJ 2152 聪聪可可(树形DP)
  10. ssh-keygen的使用方法及配置authorized_keys两台linux机器相互认证