大意:$n$结点,$m$条边无向图, 有$k$个人, 每个人最多走$\left\lceil\frac {2n}{k}\right\rceil$步, 求一种方案使得$k$个人走遍所有的点
$n$结点树的欧拉序长度为$2n-1$, 直接取$dfs$树的欧拉序即可
#include <iostream> #include <algorithm> #include <math.h> #include <cstdio> #include <vector> #define pb push_back #define REP(i,a,n) for(int i=a;i<=n;++i) using namespace std; , INF = 0x3f3f3f3f; int n, m, k, mx; int vis[N]; vector<int> g[N], path; void dfs(int x) { vis[x] = , path.pb(x); for (int y:g[x]) { if (!vis[y]) dfs(y),path.pb(x); } } int main() { cin>>n>>m>>k; REP(i,,m) { int x, y; cin>>x>>y; g[x].pb(y),g[y].pb(x); } dfs(),path.pop_back(); ; i<=k; cout<<'\n',++i) { if (path.empty()) { cout<<"1 1"; continue; } *n+k-)/k; if (mx>path.size()) mx = path.size(); cout<<mx<<' '; REP(j,,mx) { cout<<path.back()<<' '; path.pop_back(); } } }