树的性质和dfs的性质 Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E
2024-10-21 15:35:28
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 ;
}
最新文章
- OC笔记一:Objective-C简介
- 【WEB API项目实战干货系列】- API登录与身份验证(三)
- Java web项目的字符集问题
- 从本地上传整个目录到hdfs的java程序
- WPF Mahapps.Metro 设置主题样式
- 什么是Elasticsearch
- http缓存协议详解
- jQuery动画方法
- 微信小程序支付+php后端
- RestTemplate的使用
- E2040 Declaration terminated incorrectly - System.ZLib.hpp(310) ZLIB_VERSION
- 代码生成器 CodeSmith 的使用(三)
- EF简易教程,从建表到表间关系
- linux下mysql自动备份脚本
- Intellij idea的Dependencies波浪线
- Session应用之验证码
- LintCode2016年8月8日算法比赛----子树
- HDU 2897 邂逅明下 ( bash 博弈变形
- hdu1422重温世界杯(动态规划,最长子序列)
- Django--ORM基础