这两天在看虚树,的确很难理解。

不过大致的思路就是说删掉一些没有用的点,但是仍然保持树的相对结构,树上只有两种点,一个是集合点,和一些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)的更多相关文章

  1. 2018.10.19浪在ACM 集训队第一次测试赛

    2018.10.19浪在ACM 集训队第一次测试赛 待参考资料: [1]:https://blog.csdn.net/XLno_name/article/details/78559973?utm_so ...

  2. 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)

    队名:Unlimited Code Works(无尽编码)  队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...

  3. 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 ...

  4. 2017 ACM/ICPC Asia Regional Qingdao Online

    Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submi ...

  5. ACM/ICPC 之 BFS(离线)+康拓展开(TSH OJ-玩具(Toy))

    祝大家新年快乐,相信在新的一年里一定有我们自己的梦! 这是一个简化的魔板问题,只需输出步骤即可. 玩具(Toy) 描述 ZC神最擅长逻辑推理,一日,他给大家讲述起自己儿时的数字玩具. 该玩具酷似魔方, ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

  10. hduoj 4706 Children&#39;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) ...

随机推荐

  1. ORACLE--12C--多租户体系架构概念

    一,概念 1,何为多租户? 官网链接: 飞机直达>> 多租户这个概念并不是12C的新特性,而是体系架构,多租户架构使得oracle 数据库成为了一个多租户的容器数据库,也就是contain ...

  2. CAD 卸载工具,完美彻底清除干净cad各种残留注册表和文件

    是不是遇到MAYA/CAD/3DSMAX/INVENTOR安装失败?AUTODESK系列软件着实令人头疼,MAYA/CAD/3DSMAX/INVENTOR安装失败之后不能完全卸载!!!(比如maya, ...

  3. 浅谈辄止WCF:完成最基本的WCF项目(1)

    Windows Communication Foundation(WCF)是由微软开发的一系列支持数据通信的应用程序框架,可以翻译为Windows 通讯开发平台. WCF的所有服务都会公开契约.契约包 ...

  4. Tor网络介绍

    Tor网络介绍 1.Tor的全称是“The Onion Router”,“An anonymous Internet communicaton system:通过Tor访问一个地址时,所经过的节点在T ...

  5. Root用户让其他用户运行某程序

    这里以启动tomcat为例 1.安装tomcat不介绍了,自己百度 2.测试能否使用,略 3.创建tomcat用户 useradd tomcat -s /sbin/nologin 创建tomcat,禁 ...

  6. React.js 小书 Lesson16 - 实战分析:评论功能(三)

    作者:胡子大哈 原文链接:http://huziketang.com/books/react/lesson16 转载请注明出处,保留原文链接和作者信息. 接下来的代码比较顺理成章了.修改 Commen ...

  7. python 批量ping服务器

    最近在https://pypi.python.org/pypi/mping/0.1.2找到了一个python包,可以用它来批量ping服务器,它是中国的大神写的,支持单个服务器.将服务器IP写在txt ...

  8. WPF-MVVM学习心德(WinForm转WPF心德)

    接触MVVM接近一段时间了,有一点理解,写下来. 之前是做winform的,工作需要,学习wpf.优缺点就不用说类,网上一大堆.我自己理解的话,有下面几点: 1.首先是界面的xmal和界面分离:wpf ...

  9. 关于JAVA中Byte数据类型二进制赋值运算报错问题

    自从JDK7更新之后,新增了二进制变量的表示,支持将整数类型用二进制来表示,用0b开头: 例如: byte b= (byte) 0b1000_0001; short s = (short) 0b100 ...

  10. 分布式环境Tomcat多节点集群下共享目录配置,tomcat虚拟目录+nfs

    我们可能有这种场景: 集群环境下,多个web容器需要请求一个共享目录下的文件,比如保存图片或者录音文件,任意一个节点保存后其他节点需要及时获取,此时就需要目录进行同步了,否则Nginx负载到任意一个节 ...