记录编号 |
159248 |
评测结果 |
AAAAAAAAAA |
题目名称 |
超牛冠军赛 |
最终得分 |
100 |
用户昵称 |
wolf. |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
4.986 s |
提交时间 |
2015-04-20 15:21:21 |
内存使用 |
0.31 MiB |
显示代码纯文本
#include<iostream>
#include<fstream>
#include<bitset>
#include<vector>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdio>
using namespace std;
#if defined wolf
const string ok="OK";
const string kk=" ";
ofstream nnew("superbull.in",ios::app);
ifstream fin("superbull.in");
#define fout cout
#define Endl endl
#else
ifstream fin("superbull.in");
ofstream fout("superbull.out");
#endif
class llink{
public:
int m,n;
int mul;
llink(){
}
llink(int a,int b,int c,int d){
m=a;
n=b;
mul=c^d;
}
bool operator < (const llink & x)const{
return mul<x.mul;
}
};
const int IMAX=999999999;
vector<int> TT,path;
void Prim(int n){
//vector<int> path;
vector<bool> flag;
path.resize(n,0);
flag.resize(n,0);
priority_queue<llink> Q;
for(int i=0;i!=n;++i){
Q.push(llink(0,i,TT[0],TT[i]));
}
flag[0]=1;
path[0]=0;
while(!Q.empty()){
llink it;
it=Q.top();
//cout<<TT[it.n]<<endl;
Q.pop();
if(flag[it.n]){
continue;
}
flag[it.n]=1;
path[it.n]=it.m;
for(int i=0;i!=n;++i){
if(flag[i]==0){
//cout<<"push"<<TT[it.n]<<kk<<TT[i]<<endl;
Q.push(llink(it.n,i,TT[it.n],TT[i]));
}
}
}
/*for(int i=0;i!=path.size();++i){
cout<<TT[i]<<kk<<TT[path[i]]<<endl;
}*/
}
long long core(int n){
long long ans=0;
vector<bool> flag;
flag.resize(n,0);
for(int i=0;i!=flag.size();++i){
ans+=(TT[i]^TT[path[i]]);
}
return ans;
}
int main(){
int n;
fin>>n;
for(int i=0;i!=n;++i){
int e;
fin>>e;
TT.push_back(e);
}
Prim(n);
fout<<core(n)<<endl;
//-------------------------*/
#if defined wolf
cout<<endl<<(double)clock()/CLOCKS_PER_SEC<<'s'<<endl;
#endif
return 0;
}
//Designed by wolf
//Mon Apr 20 2015