首页 > 其他分享 >P6066 [USACO05JAN] Watchcow S

P6066 [USACO05JAN] Watchcow S

时间:2023-09-27 15:12:13浏览次数:26  
标签:cnt P6066 Watchcow ne tot dfs rl ll USACO05JAN

prologue

这个题这么水的一个板子题。

analysis

这个题目我们正反建两条边,在跑欧拉回路的时候,看这个边是不是被走过,走过就不走,跳过这个边。如果没走,就走这条边并且标记这个边走过了。

code time

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rl register ll 

const ll N = 2e4 + 10, M = 1e5 + 10;

ll n, m;

ll tot, ne[M], e[M], h[N], ans[M], cnt;

bool rm[M];

inline void add(ll a, ll b)
{
    ne[++tot] = h[a], h[a] = tot, e[tot] = b;
}

inline void dfs(ll u)
{
    for(rl i=h[u]; ~i; i = ne[i])
    {
        if(rm[i]) continue;

        rm[i] = true;

        ll v = e[i];
        dfs(v);
    }
    ans[++cnt] = u;
}

int main()
{
    freopen("1.in", "r", stdin), freopen("1.out", "w", stdout);
    cin >> n >> m;
    
    memset(h, -1, sizeof h);

    for(rl i=1; i <= m; ++ i)
    {
        ll a, b;
        cin >> a >> b;
        add(a, b), add(b, a);
    }

    dfs(1);

    for(rl i=cnt; i; -- i) cout << ans[i] << endl;
    return 0;
}

标签:cnt,P6066,Watchcow,ne,tot,dfs,rl,ll,USACO05JAN
From: https://www.cnblogs.com/carp-oier/p/17732760.html

相关文章

  • P6066 Watchcow S
    \(P6066\)\(Watchcow\)\(S\)一、题目描述\(Farmer\)\(John\)有\(N\)个农场(\(2≤N≤10^4\)),这些农场由\(M\)条道路连接(\(1\leqM\leq5\times10^4\))。不保证没有重边。\(Bassie\)从\(1\)号农场开始巡逻,每条路必须从两个方向各走恰好一遍,最后回到\(1\)号农场。请输出一......