求助,不知道错在哪里了

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

克尔苏加德 @ 2022-09-13 09:21:18

74pts

#include<iostream>
#include<cmath> 
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int map[510][510];
int n = 1,m;
int f[1025],num[510];

void Euler(int k,int now){
    for(int i = 1; i <= n; i ++)
        if(map[now][i] != 0){
            map[now][i] --;
            map[i][now] --;
            Euler(k + 1,i);
        }
    f[k] = now;
}

int main(){
    cin>>m;
    memset(map,0,sizeof(map));
    memset(num,0,sizeof(num));
    for(int i = 1; i <= m; i ++){
        int u,v;
        cin>>u>>v;
        n = max(n,u);
        n = max(n,v);
        map[u][v] ++;
        map[v][u] ++;
        num[u] ++;
        num[v] --;
    }
    int s = 1;
    for(int i = 1; i <= n; i ++)
        if(num[i] % 2){
            s = i;
            break;
        }
    Euler(1,s);
    for(int i = 1; i <= m + 1; i ++)
        cout<<f[i]<<endl;
    return 0;
}

100pts

#include<iostream>
#include<cmath> 
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int map[510][510];
int n = 1,m;
int ans = 0;
int f[1025],num[510];

void Euler(int now){
    for(int i = 1; i <= n; i ++)
        if(map[now][i] != 0){
            map[now][i] --;
            map[i][now] --;
            Euler(i);
        }
    f[++ ans] = now;
}

int main(){
    cin>>m;
    memset(map,0,sizeof(map));
    memset(num,0,sizeof(num));
    for(int i = 1; i <= m; i ++){
        int u,v;
        cin>>u>>v;
        n = max(n,u);
        n = max(n,v);
        map[u][v] ++;
        map[v][u] ++;
        num[u] ++;
        num[v] --;
    }
    int s = 1;
    for(int i = 1; i <= n; i ++)
        if(num[i] % 2){
            s = i;
            break;
        }
    Euler(s);
    for(int i = m + 1; i >= 1; i --)
        cout<<f[i]<<endl;
    return 0;
}

感觉没啥区别啊,就是多了个全局变量?


|