比赛 20110923 评测结果 AAAWWWWWWW
题目名称 拜访奶牛 最终得分 30
用户昵称 苏轼 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2011-09-23 21:08:52
显示代码纯文本
#include <cstdio>
#include <cstdlib>

using namespace std;

struct way_t {
    int st, en;
};

way_t way[100010];
int f[50001], wtrue, wfalse, waytail;
bool boo[50001];

int comp (const void *pa, const void *pb)
{
    way_t *a = (way_t*)pa, *b = (way_t*)pb;
    return a->st - b->st;
}

void go (const int wh, const bool color)
{
    color ? wtrue++ : wfalse++;

    boo[wh] = true;
    for (int i=f[wh]; way[i].st==wh; i++)
        if (!boo[way[i].en])
            go(way[i].en, !color);
}

int main ()
{
    freopen("vacation.in", "r", stdin);
    freopen("vacation.out", "w", stdout);

    int N;
    scanf("%d", &N);
    for (int i=0; i<N; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        
        way[waytail].st = a, way[waytail].en = b;
        waytail++;
        way[waytail].st = b, way[waytail].en = a;
        waytail++;
    }

    qsort(way, waytail, sizeof(way_t), comp);

    f[1] = 0;
    for (int i=0, j=1; i<waytail; i++)
        if (way[i].st > j)
            f[++j] = i;

    go(1, false);

    printf("%d\n", wtrue>wfalse ? wtrue:wfalse);

    return 0;
}