BZOJ 3943 Usaco2015 Feb SuperBull Prim

题目大意

异或Prim。

思路

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

CODE

#define _CRT_SECURE_NO_WARNINGS

#include 
#include 
#include 
#include 
#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;
}

你可能感兴趣的:(Prim,BZOJ,USACO,BZOJ,USACO,Prim,最大生成树)