WA88求助

P2731 [USACO3.3] 骑马修栅栏 Riding the Fences

遥遥领先 @ 2023-07-09 13:52:28

#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 5000;
int mp[N][N];
int deg[N];
int ans[N];
int tot;
void dfs(int a)
{
    for (int i = 1;i <= n;i++)
    {
        if (mp[a][i] >= 1)
        {
            mp[a][i]--;
            mp[i][a]--;
            dfs(i);
        }
    }
    tot++;
    ans[tot] = a;
}
int main()
{
    cin >> n;
    for (int i = 1;i <= n;i++)
    {
        int x,y;
        cin >> x >> y;
        mp[x][y]++;
        mp[y][x]++;
        deg[x]++;
        deg[y]++;
        n = max({n,x,y});
    }
    int s = 1;
    for (int i = 1;i <= n;i++)
    {
        if (deg[i] % 2)
        {
            s = i;
            break;
        }
    }
    dfs(s);
    while (tot)
    {
        cout << ans[tot] << '\n';
        tot--;
    }
    return 0;
}

by 遥遥领先 @ 2023-07-09 14:08:06

我已经调出来了


|