ACM-ICPC (10/19)
这两天在看虚树,的确很难理解。
不过大致的思路就是说删掉一些没有用的点,但是仍然保持树的相对结构,树上只有两种点,一个是集合点,和一些LCA,这些LCA是为了保持树的相对结构,才留下的。
具体做法网上说的天花乱坠,我实在是想吐槽。作为新人没有什么很好的入门资料,大佬们也是含含糊糊,就是一顿套模板了(和图论一样),反正做题也是在新树上重新DP~~~
附上BZOJ2286的模板例子,我删减了一部分。根据题意来~~~
具体的原理我也不想管了。ヾ(◍°∇°◍)ノ゙ who care who 呢?
#include<iostream>
#include<set>
#include<map>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<stack>
#define inf 1e60
#define pa pair<int,int>
#define ll long long
using namespace std; int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} int bin[];
int n,m,cnt,ind,top;
int last[],last2[],fa[][];
ll mn[],f[];
int h[],mark[],deep[];
int st[]; struct edge{
int to,next,v;
}e[],ed[]; void insert(int u,int v,int w)
{
e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;e[cnt].v=w;
e[++cnt].to=u;e[cnt].next=last[v];last[v]=cnt;e[cnt].v=w;
} void insert2(int u,int v) //单向边了,也可以是双向的。
{ if(u==v)return;
printf("%d--->%d\n",u,v);
ed[++cnt].to=v;ed[cnt].next=last2[u];last2[u]=cnt;
} bool cmp(int a,int b)
{
return mark[a]<mark[b];
} void pre(int x)
{
mark[x]=++ind;
for(int i=;bin[i]<=deep[x];i++)
fa[x][i]=fa[fa[x][i-]][i-];
for(int i=last[x];i;i=e[i].next)
if(e[i].to!=fa[x][])
{
mn[e[i].to]=min(mn[x],(ll)e[i].v);
deep[e[i].to]=deep[x]+;
fa[e[i].to][]=x;
pre(e[i].to);
}
} int lca(int x,int y)
{
if(deep[x]<deep[y])swap(x,y);
int t=deep[x]-deep[y];
for(int i=;bin[i]<=t;i++)
if(t&bin[i])x=fa[x][i];
for(int i=;i>=;i--)
if(fa[x][i]!=fa[y][i])
x=fa[x][i],y=fa[y][i];
if(x==y)return x;
return fa[x][];
} void dp(int x)
{
f[x]=mn[x];
ll tmp=;
for(int i=last2[x];i;i=ed[i].next)
{
dp(ed[i].to);
tmp+=f[ed[i].to];
}
last2[x]=;
if(tmp==)f[x]=mn[x];
else if(tmp<=f[x])f[x]=tmp;
} void solve()
{
cnt=;
int K=read();
for(int i=;i<=K;i++)
h[i]=read();
sort(h+,h+K+,cmp);
int tot=K;
// h[++tot]=h[1];
// for(int i=2;i<=K;i++) {
// int tmp = lca(h[tot],h[i]);
// if(lca(h[tot],h[i])!=h[tot])
// h[++tot]=h[i];
// } st[++top]=; //top栈指针
for(int i=;i<=tot;i++)
{
int now=h[i],f=lca(now,st[top]);
while()
{
if(deep[f]>=deep[st[top-]])
{
insert2(f,st[top--]);
if(st[top]!=f)st[++top]=f;
break;
}
insert2(st[top-],st[top]);top--;
}
if(st[top]!=now)st[++top]=now;
} while(--top)insert2(st[top],st[top+]);
dp();
printf("%lld\n",f[]);
} int main()
{
freopen("in.txt","r",stdin);
bin[]=;for(int i=;i<;i++)bin[i]=bin[i-]<<;
n=read();
for(int i=;i<n;i++)
{
int u=read(),v=read(),w=read();
insert(u,v,w);
}
mn[]=inf;pre();
m=read();
for(int i=;i<=m;i++)
solve();
return ;
}
最近两天的训练效果不咋样,心思太杂了,我得调整调整,好好A题吧~~~
具体方案就是看论文,做经典题吧~~~
详细论文:
2015集训队论文集
《浅谈字符串匹配的几种方式》
《后缀数组》
《后缀自动机及其应用》
《生成函数的运用与组合计数问题》
2016集训队论文
《网络流的一些建模方法》
《再探快速傅里叶变换》
DP专题:
http://www.cnblogs.com/qscqesze/p/4614733.html
ACM-ICPC (10/19)的更多相关文章
- 2018.10.19浪在ACM 集训队第一次测试赛
2018.10.19浪在ACM 集训队第一次测试赛 待参考资料: [1]:https://blog.csdn.net/XLno_name/article/details/78559973?utm_so ...
- 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)
队名:Unlimited Code Works(无尽编码) 队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...
- 2016 ACM/ICPC Asia Regional Qingdao Online(2016ACM青岛网络赛部分题解)
2016 ACM/ICPC Asia Regional Qingdao Online(部分题解) 5878---I Count Two Three http://acm.hdu.edu.cn/show ...
- 2017 ACM/ICPC Asia Regional Qingdao Online
Apple Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submi ...
- ACM/ICPC 之 BFS(离线)+康拓展开(TSH OJ-玩具(Toy))
祝大家新年快乐,相信在新的一年里一定有我们自己的梦! 这是一个简化的魔板问题,只需输出步骤即可. 玩具(Toy) 描述 ZC神最擅长逻辑推理,一日,他给大家讲述起自己儿时的数字玩具. 该玩具酷似魔方, ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time
Problem D. Delay Time Input file: standard input Output file: standard output Time limit: 1 second M ...
- hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...
- hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- hduoj 4707 Pet 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4707 Pet Time Limit: 4000/2000 MS (Java/Others) Memory ...
- hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4706 Children's Day Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- 利用httpClient发起https请求
HttpClientBuilder b = HttpClientBuilder.create();// setup a Trust Strategy that allows all certifica ...
- oracle 基础知识(三)--SCN
一,SCN的介绍 SCN(System Change Number),也就是通常所说的系统改变号或者系统提交号,是数据库中非常重要的一个数据结构. SCN用以标识数据库在某个确切时刻提交的版本 ...
- rancher 2.X 搭建小型web集群+mysql主从复制
一,环境配置 rancher 2.1.6 二,配置harbor私有仓库 见上文 三,配置私有镜像 01,总文件 dockerfile 为主配置文件,html 为站点文件wordpress.,官网 ...
- (转)CentOS 7 sytemctl 自定义服务开机启动
CentOS 7 sytemctl 自定义服务开机启动 原文:http://blog.csdn.net/ithomer/article/details/51766319 CentOS 7继承了RHEL ...
- 解决IE9 IE8的跨域 请求问题
/// <summary> /// 根据url获取对应的HTML /// </summary> /// <param name="url">&l ...
- TT8509: PL/SQL execution terminated; PLSQL_TIMEOUT exceeded
TT8509: PL/SQL execution terminated; PLSQL_TIMEOUT exceeded plsql_timeout连接超时,解决办法: ODBC pl/sql选项卡 修 ...
- 第十六章:自定义push notification sound
前面一节已经讲过如何在ionic中集成jpush,这样我们的hybrid app在部署到ios或者android上面的时候,就可以接收通知了.如果不满足系统自带的声音,可以通过一些方式来播放自定义的通 ...
- Java工程路径及相对路径(转载)
3. 新建文件,默认位于工程目录new File("xxx.txt").getAbsolutePath();例如输出,D:\workspaces\workspace1\myProj ...
- 正则表达式过滤联系方式,微信手机号QQ等
有些输入不允许用户输入联系方式.可以使用以下正则表达式来判断是否输入敏感信息 var reg = new RegExp("(微信|QQ|qq|weixin|1[0-9]{10}|[a-zA- ...
- node.js压缩和解压缩
推荐一个极其简单.及其好用的node.js的压缩和解压缩类库 compressing 支持格式: tar.gzip.tgz.zip 以zip为例,tar,tgz和gzip与zip相同. 压缩文件: ...