Underground Lab CodeForces - 782E (欧拉序)

Posted uid001

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Underground Lab CodeForces - 782E (欧拉序)相关的知识,希望对你有一定的参考价值。

大意:$n$结点,$m$条边无向图, 有$k$个人, 每个人最多走$leftlceilfrac {2n}{k} ight ceil$步, 求一种方案使得$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;

const int N = 4e5+10, INF = 0x3f3f3f3f;
int n, m, k, mx;
int vis[N];
vector<int> g[N], path;

void dfs(int x) {
    vis[x] = 1, path.pb(x);
    for (int y:g[x]) {
        if (!vis[y]) dfs(y),path.pb(x);
    }
}

int main() {
    cin>>n>>m>>k;
    REP(i,1,m) {
        int x, y;
        cin>>x>>y;
        g[x].pb(y),g[y].pb(x);
    }
    dfs(1),path.pop_back();
    for (int i=1; i<=k; cout<<‘
‘,++i) {
        if (path.empty()) { 
            cout<<"1 1";
            continue;
        }
        int mx = (2*n+k-1)/k;
        if (mx>path.size()) mx = path.size();
        cout<<mx<< ;
        REP(j,1,mx) {
            cout<<path.back()<< ;
            path.pop_back();
        }
    }
}

 

以上是关于Underground Lab CodeForces - 782E (欧拉序)的主要内容,如果未能解决你的问题,请参考以下文章

leetcode1396. Design Underground System

URAL 1205 By the Underground or by Foot?(SPFA)

Codeforces 832D - Misha, Grisha and Underground

Misha, Grisha and Underground CodeForces - 832D (倍增树上求LCA)

Aug.26(Tonight)UNDERGROUND MOVEMENT & JULIANA LIMA BIRTHDAY BASH

Codeforces 832 D Misha, Grisha and Underground