# 危险路径(启发式合并+mst)

fu=u!=vd(u,v)$f_u=\sum_{u!=v}d(u,v)$
i=1n(if(i))$\mathop{\oplus}\limits_{i = 1}^{n}{\left(i \cdot f(i)\right)}$

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int T,n,m;
#define MAXN (112345)
class bingchaji
{
public:
int father[MAXN],n,cnt,sz[MAXN];
vector<pair<ull,ull> > g[MAXN];
ull sum[MAXN];
void mem(int _n)
{
n=cnt=_n;
For(i,n) {
father[i]=i,sz[i]=1;
sum[i]=0; g[i].resize(0);
g[i].pb(mp(i,0));
}
}
int getfather(int x)
{
if (father[x]==x) return x;

return father[x]=getfather(father[x]);
}
void unite(int x,int y)
{
x=getfather(x);
y=getfather(y);
if (x^y) {
--cnt;
father[x]=y;
sz[y]+=sz[x];
}
}
bool same(int x,int y)
{
return getfather(x)==getfather(y);
}
}S;
#define MAXM (312345)
struct edge{
int u,v;
ull w;
friend bool operator<(edge a,edge b){
return a.w<b.w;
}
}e[MAXM];

int main()
{
//  freopen("g.in","r",stdin);
//  freopen(".out","w",stdout);
For(kcase,T) {
For(i,m) {
}
sort(e+1,e+1+m);
S.mem(n);
For(i,m) {
{
int t1=e[i].u,t2=e[i].v;
ull v=e[i].w;
t1=S.getfather(t1);
t2=S.getfather(t2);
if(t1==t2) continue;

if (S.sz[t1]>S.sz[t2]) swap(t1,t2);
S.sum[t1]+=S.sz[t2]*v;
S.sum[t2]+=S.sz[t1]*v;
S.sz[t2]+=S.sz[t1];
for(pair<ull,ull> p:S.g[t1] ) {
S.g[t2].pb(mp(p.fi,p.se+S.sum[t1]-S.sum[t2]));
}
S.father[t1]=t2;

}
}
ull ret=0;
int u=S.getfather(1);
ull t=S.sum[u];
for(auto p:S.g[u]) {
ret^=1ULL * p.fi*(p.se+t);
}
printf("Case #%d: ",kcase);
cout<<ret<<endl;
}
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120