2018徐州现场赛A
题目链接:http://codeforces.com/gym/102012/problem/A
题目给出的算法跑出的数据是真的水
#include<iostream>
#include<algorithm>
using namespace std;
unsigned long long k1,k2;
#define inf 0x3f3f3f3f
#define mod 1000000007
int tot;
unsigned long long xo()
{
unsigned long long k3=k1,k4=k2;
k1=k4;
k3^=k3<<;
k2=k3^k4^(k3>>)^(k4>>);
return k2+k4;
}
struct edge{
int u,v;
unsigned long long w;
bool operator <(const edge &a)const{
return w<a.w;
}
}e[];
int n,m,fa[],cnt;
unsigned long long ans;
void add(int u,int v,unsigned long long w)
{
e[++cnt].u=u;
e[cnt].v=v;
e[cnt].w=w;
}
void gen()
{
int u,v;
unsigned long long w;
scanf("%d%d%llu%llu",&n,&m,&k1,&k2);
cnt=;
for(int i=;i<=m;i++)
{
u=xo()%n+;
v=xo()%n+;
w=xo();
add(u,v,w);
}
}
int _find(int u)
{
if(fa[u]==u)return u;
return fa[u]=_find(fa[u]);//路径压缩
}
unsigned long long solve()
{
tot=;
sort(e+,e++cnt);
int u,v,x,y;
unsigned long long w;
ans=;
for(int i=;i<=n;i++)
fa[i]=i;
for(int i=;i<=cnt;i++)
{
u=e[i].u;v=e[i].v;w=e[i].w;
x=_find(u);y=_find(v);
if(x!=y)
{
ans=(ans+w)%mod;
tot++;
fa[y]=x;
if(tot==n)return ans;
}
}
return ;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
gen();
ans=inf;
printf("%llu\n",solve());
}
return ;
}
2018徐州现场赛A的更多相关文章
- 2018 icpc 徐州现场赛G-树上差分+组合数学-大佬的代码
现场赛大佬打印的代码,观摩了一哈. 写了注释,贴一下,好好学习.%%%PKU 代码: //树上差分(LCA) #include<bits/stdc++.h> #define For(i,x ...
- 2018徐州网络赛 - Trace
题意:n个左下角为原点右上角在第一象限的矩形不断覆盖,求最后形成的图形的周长 x和y是独立的,分别维护两棵线段树,一棵表示x坐标下最大的y值,另一棵表示y坐标下最大的x值 从覆盖的角度来考虑,如果逆序 ...
- ACM-ICPC 2018徐州网络赛-H题 Ryuji doesn't want to study
死于update的一个long long写成int了 真的不想写过程了 ******** 树状数组,一个平的一个斜着的,怎么斜都行 题库链接:https://nanti.jisuanke.com/t/ ...
- 2018徐州网络赛H. Ryuji doesn't want to study
题目链接: https://nanti.jisuanke.com/t/31458 题解: 建立两个树状数组,第一个是,a[1]*n+a[2]*(n-1)....+a[n]*1;第二个是正常的a[1], ...
- 2018南京现场赛K 随机输出
题目链接:http://codeforces.com/gym/101981/attachments n和m太小,空地联通无环,总步数太大,直接随机输出5w个方向 #include<iostrea ...
- 2018南京现场赛D 模拟退火
题目链接:https://codeforces.com/gym/101981/attachments 给你n个城市的三维坐标,叫你求得一个坐标使这个坐标到其他城市的最大距离最小,并输出这个距离(距离不 ...
- 2019icpc徐州现场赛 H Yuuki and a problem (树状数组套主席树)
题意 2e5的数组,q个操作 1.将\(a[x]\)改为y 2.求下标l到r内所有的\(a[i]\)通过加法不能构成的最小的值 思路 通过二操作可以知道需要提取l到r内的值及其数量,而提取下标为l到r ...
- 2018 ICPC 徐州网络赛
2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...
- Ryuji doesn't want to study 2018徐州icpc网络赛 树状数组
Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, ea ...
随机推荐
- poj1080 - Human Gene Functions (dp)
题面 It is well known that a human gene can be considered as a sequence, consisting of four nucleotide ...
- 2018-2-13-C#-动态加载卸载-DLL
title author date CreateTime categories C# 动态加载卸载 DLL lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:2 ...
- keil中使用_at_绝对地址定位问题
最近在做51单片机的时候,看到程序中某头文件有这样一段: 其中,_at_的作用就是将变量限定存放在指定的RAM空间.比如在这个单片机头文件中,就是将变量P00F,P01F分别存到Addr(0x8000 ...
- 十二、格式化I/O
1.fprintf 表头文件 #include<stdio.h> 定义函数 int fprintf(FILE * stream, const char * format,.......); ...
- kali添加路由
kali添加路由 vim /etc/network/interfaces iface eth0 inet static address 192.168.1.10 netmask 255.255.255 ...
- markdown color
深青色 深蓝色 seagreen darkgreen indianred cornflowerblue lightskyblue coral lightcoral darkorange
- 关于java继承的哪些事
引言 本文结合一个例子来说明继承实现的基本原理. 基类Base代码如下所示: public class Base { public static int s; private int a; stati ...
- 【萌新向】cartographer_ros最新安装指南 2019-12
首先说明,这篇文章于2019年12月写下,cartographer现在还在不断更新,也许这篇文档内容会失效,但是大体是一样的安装流程. 一.硬件条件 使用平台 x86_64平台 ROS发行版 Indi ...
- JWT实现分布式Session
JWT是什么 JWT一看就是简称,它的全称JSON Web Token,从字面上我们看出 1.数据是JSON格式 2.用于Web应用 3.是一个Token,也就是一个令牌方式 看看官方的说明,它定义了 ...
- ulimit -u 解决 Jenkins OOM 错误
Apr 24, 2018 11:19:48 AM hudson.init.impl.InstallUncaughtExceptionHandler$DefaultUncaughtExceptionHa ...