码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ 3943 Usaco2015 Feb SuperBull Prim

时间:2015-04-09 17:30:46      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:bzoj   usaco   prim   最大生成树   

题目大意

异或Prim。

思路

没开long long WA了一次你敢信?

CODE

#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAX 2010
#define INF 0x3f3f3f3f
using namespace std;

int points;
int src[MAX];

int f[MAX];
bool v[MAX];

long long Prim()
{
    long long re = 0;
    for(int i = 1; i <= points; ++i) {
        int max_length = 0, p = 1;
        for(int j = 1; j <= points; ++j)
            if(!v[j] && f[j] > max_length)
                max_length = f[j], p = j;
        v[p] = true;
        re += max_length;
        for(int j = 1; j <= points; ++j)
            if(!v[j])
                f[j] = max(f[j], src[p]^src[j]);
    }
    return re;
}

int main()
{
    cin >> points;
    for(int i = 1; i <= points; ++i)
        scanf("%d", &src[i]);
    cout << Prim() << endl;
    return 0;
}

BZOJ 3943 Usaco2015 Feb SuperBull Prim

标签:bzoj   usaco   prim   最大生成树   

原文地址:http://blog.csdn.net/jiangyuze831/article/details/44961687

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!