lightoj 1250 - Village Postman

找欧拉回路;开始看错题了,,,抓狂抓狂笨啊。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#define LL long long
#define DB double

using namespace std;
const int N = 209;
const int M = 1009;
const int INF = 0x3f3f3f3f;
int n,m;
int re[N];
int ans;
int path[M],cnt;
int in[N];
struct LT{
    int to,nex;
} L[M<<1];
int F[N],C=2;
int v[M];
void add(int f,int t){
    L[C].nex = F[f];L[C].to = t;
    F[f] = C++;
}
void dfs(int k){
    for(int i=F[k];i;i=L[i].nex){
        if(v[i>>1]) continue;
        int to = L[i].to;
        v[i>>1] = 1;
        dfs(to);
    }
    path[cnt++] = k;
}
void solve(int T)
{
    ans =0;
    for(int i=1;i<=n;i++)
        ans += re[i];
    ans = ans-(n+1)*n/2-m;
    cnt = 0;
    in[1]--;
    dfs(1);
    printf("Case %d: %d\n",T,ans);

    for(int i=0;i<cnt;i++)
    {
        if(i) printf(" ");printf("%d",path[i]);
    }puts("");
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    int cas,T=1;scanf("%d",&cas);
    while(cas--)
    {
        scanf("%d%d",&n,&m);
        ans =0;cnt = 0;C=2;
        memset(in,0,sizeof(in));
        memset(F,0,sizeof(F));
        memset(v,0,sizeof(v));
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&re[i]);
        }
        int a,b;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&a,&b);
            add(a,b);add(b,a);
            in[a]++;in[b]++;
        }
        solve(T);T++;
    }
    return 0;
}


你可能感兴趣的:(欧拉回路)