bzoj3918 [Baltic2014]Postman

Posted 逢山开路 遇水架桥

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bzoj3918 [Baltic2014]Postman相关的知识,希望对你有一定的参考价值。

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3918

【题解】

每日至少更一题啊qwq凑任务(迷

明显猜个结论:随便搜环就行了

然后搜环姿势错了我也很无奈啊。。。

技术分享
# include <stdio.h>
# include <string.h>
# include <algorithm>
// # include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 1500000 + 10;
const int mod = 1e9+7;

# define RG register
# define ST static

int n, m;
int head[M], nxt[M], to[M], tot = 1;
inline void add(int u, int v) {
    ++tot; nxt[tot] = head[u]; head[u] = tot; to[tot] = v; 
}
inline void adde(int u, int v) {
    add(u, v);
    add(v, u);
}

bool vis[M]; 
int Final;
int c[M], cn, p[M];
 
inline void dfs(int x) {
    if(p[x] != -1) {
        printf("%d", x);
        for (int i=p[x]+1; i<=cn; ++i) {
            printf(" %d", c[i]);
            p[c[i]] = -1;
        }
        puts(""); 
        cn = p[x];
        return;
    }
    c[++cn] = x;
    p[x] = cn;
    for (int i=head[x]; i; i=nxt[i]) {
        if(vis[i] || vis[i^1]) continue;
        head[x] = nxt[i];
        vis[i] = 1;
        dfs(to[i]);
        if(p[x] == -1) break;
    }
}


int main() {
    scanf("%d%d", &n, &m);
    for (int i=1; i<=m; ++i) {
        int u, v; scanf("%d%d", &u, &v);
        adde(u, v);
    }
    
    for (int i=1; i<=n; ++i) p[i] = -1;
    
    for (int i=2; i<=tot; i++) 
        if(!vis[i] && !vis[i^1]) 
            dfs(to[i]); 

    return 0;
}
View Code

 

以上是关于bzoj3918 [Baltic2014]Postman的主要内容,如果未能解决你的问题,请参考以下文章

bzoj 1367: [Baltic2004]sequence

bzoj 1367: [Baltic2004]sequence

[bzoj 1367][Baltic2004]sequence

bzoj2348[Baltic 2011]Plagiarism*

BZOJ1367[Baltic2004]sequence 左偏树

bzoj1355Baltic2009Radio Transmission