88分,WA一个点

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

ltcy123456 @ 2023-07-18 10:27:06

#include<bits/stdc++.h>
using namespace std;
int n,maxn,b=10000,f[1025][1025];
int p[1025],d[1025],start,num;
void dfs(int i){
    for(int j=b;j<=maxn;j++)
        if(f[i][j]){
            f[i][j]--;
            f[j][i]--;
            dfs(j);
        }
    p[++num]=i;
}
int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        int x,y; cin >> x >> y;
        f[x][y]++;
        f[y][x]++;
        d[x]++; d[y]++;
        b=min(min(x,y),b);
        maxn=max(max(x,y),maxn);
    }
    for(int i=b;i<=maxn;i++)
        if(d[i]%2){
            start=i; break; 
        }
    dfs(start);
    for(int i=num;i>=1;i--)
        cout << p[i] << endl; 
    return 0;
}

by dingjingyi @ 2023-07-24 13:08:03

@ltcy123456,是第二个点吗


by dingjingyi @ 2023-07-24 13:09:36

start默认为1,为0会WA


by hz20210123 @ 2023-08-06 15:05:22

题目中好像说了编号从一开始吧,应该可以不用再去定义b


|