Codeforces Round #403 (Div. 2) E. Underground Lab
来源:互联网 发布:淘宝商品名称 靠前 编辑:程序博客网 时间:2024/06/05 18:01
题意:给n点m边的连通图,k个人从任意点出发至多经过 个点,求分配方式使得每个点都至少被走过一次
题解:在图中以任意点为根任意dfs出一个生成树,每条边走2次(也就是每次向前走完再回头走),按dfs的顺序得出一个答案序列,总共走过2*(n-1)+1 = 2*n-1个点并且走完所有点,再把连续的 个点分配给一个人,多的人输出1 1即可
#include <iostream>#include <cstdio>#include <cctype>#include <algorithm>#include <cstring>#include <string>#include <cmath>#include <vector>#include <set>#include <stack>#include <sstream>#include <queue>#include <map>#include <functional>#include <bitset>using namespace std;#define pb push_back#define ll long long#define ull unsigned long long#define pii pair<int, int>#define mk make_pair#define fi first#define se second#define ALL(A) A.begin(), A.end()#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)#define repr(i, n) for(int (i)=(int)(n);(i)>=0;(i)--)#define repab(i,a,b) for(int (i)=(int)(a);(i)<=(int)(b);(i)++)#define reprab(i,a,b) for(int (i)=(int)(a);(i)>=(int)(b);(i)--)#define sc(x) scanf("%d", &x)#define pr(x) printf("x:%d\n", x)#define fastio ios::sync_with_stdio(0), cin.tie(0)#define frein freopen("in.txt", "r", stdin)#define freout freopen("out.txt", "w", stdout)#define freout1 freopen("out1.txt", "w", stdout)#define lb puts("")#define PI M_PI#define debug cout<<"???"<<endl#define mid ((l+r)>>1)const ll mod = 1000000007;//const int INF = 0x3f3f3f3f;const ll INF = 0x3f3f3f3f3f3f3f3f;const double eps = 1e-6;template<class T> T gcd(T a, T b){if(!b)return a;return gcd(b,a%b);}const int maxn = 2e5+10;vector<int> ans, edg[maxn];int n,m,k,vis[maxn];void dfs(int u){ vis[u] = 1; ans.pb(u); for(int i = 0; i < edg[u].size(); i++){ int v = edg[u][i]; if(vis[v]) continue; dfs(v); ans.pb(u); }}int main(){ //frein; cin >> n >> m >> k; for(int i = 0; i < m; i++){ int u,v; sc(u); sc(v); edg[u].pb(v); edg[v].pb(u); } dfs(1); int stp = (2*n+k-1)/k; for(int i = 0; i < k; i++){ int beg = i*stp, ed = min((i+1)*stp, (int)ans.size()); if(ed <= beg){ printf("1 1\n"); continue; } printf("%d", ed-beg); for(int j = beg; j < ed; j++){ printf(" %d", ans[j]); } lb; } return 0;}
阅读全文
0 0
- Codeforces Round #403 (Div. 2) E. Underground Lab
- Codeforces Round #403 E. Underground Lab(思维+搜索)
- Codeforces Round #403 C. Underground Lab(脑洞)
- 【Codeforces Round #403】Codeforces 781C Underground Lab
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) E
- Codeforces Round #425 (Div. 2)D. Misha, Grisha and Underground
- Codeforces Round #425 (Div. 2) D.Misha, Grisha and Underground
- Codeforces Round #425 (Div. 2) D. Misha, Grisha and Underground
- Codeforces 782E Underground Lab【极限思维+Dfs】
- Codeforces Round #425 (Div. 2) D. Misha, Grisha and Underground LCA模版
- Codeforces Round #425 (Div. 2) D. Misha, Grisha and Underground LCA
- Codeforces Round #425 (Div. 2)D. Misha, Grisha and Underground(LCA)
- Codeforces Round #425 (Div. 2) D. Misha, Grisha and Underground 最近公共祖先
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces Round #403 (Div. 2)(A-E 未完)
- Codeforces Round #103 (Div. 2) E题
- Codeforces Round #147 (Div. 2) E
- Codeforces Round #184 (Div. 2) D、E
- js异常 missing ) after argument list 解决方案
- Algorithm之路一:Two Sum
- Android.mk和Application.mk配置参数详解
- 【Scikit-Learn 中文文档】机器学习: scikit-learn 中的设置以及预估对象
- 问题 D: 输入入门(3)
- Codeforces Round #403 (Div. 2) E. Underground Lab
- js编码的实用技巧(二)
- spring-boot入门(一)快速搭建一个web应用
- TLV格式及编码
- NumPy v1.13
- 消极软件工程师小王:第3工作日——BigDecimal
- JDBC-Mybatis总结
- 【Scikit-Learn 中文文档】监督学习:从高维观察预测输出变量
- Mac:VSCode 批量替换快捷键