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) ...
随机推荐
- PIE SDK算法的自定义扩展
1.算法功能简介 算法的自定义扩展允许用户自主开发新的算法.自定义的算法必须实现PIE.SystemAlgo.BaseSystemAlgo基础类,这样才能被PIE的算法管理器调用起来. 2.算法功能实 ...
- JS实现跨域请求数据--jsonp
* { margin: 0; padding: 0; } input { width: 300px; height: 30px; border: 1px solid lightgray; margin ...
- javascript中构造函数与普通函数的区别还有关于“new”操作符的一些原理
有一种创建对象的方法叫做工厂模式,例如: function person(name,age){ var o=new Object(); o.name=name; o.age=age; return o ...
- 数据库nomount mount open阶段走向
先来简要了解一下Oracle数据库体系架构以便于后面深入理解,Oracle Server主要由实例(instance)和数据库(database)组成.实例(instance)由共享内存(SGA)和后 ...
- jackson工具类有动态属性过虑功能
在业务应用中经常会有指定属性序列化json的需求,C#中这个功能很容易就可以解决:使用lambda重新构造一下匿名对象就可以了.一行代码搞定.java是这样解决的. public JsonMapper ...
- TOJ 3031 Multiple
Description a program that, given a natural number N between 0 and 4999 (inclusively), and M distinc ...
- mvc 中Request[""]与Request.QueryString[""]
1.Request[""]与Request.QueryString[""]获取不到值时返回null: 2.Request[""]与Reque ...
- 梁宇轩 mysql 语句学习一 对表的操作
1.SHOW TABLES; -- 查询库中所有的表 2 .CREATE TABLE test(id INT(20) PRIMARY KEY NOT NULL AUTO_INCRE ...
- IO流之File类
IO概述: 程序数据都是在内存中,程序运行结束,这些数据将清空,数据都都不能保存下来,下次程序启动的时候,想再把这些数据读出来继续使用,把数据持久化存储,就需要把内存中的数据存储到内存以外的其他持久化 ...
- csharp: ClientScript.RegisterStartupScript int net4.0
//彈出提示 ClientScriptManager cs = Page.ClientScript; StringBuilder sb = new StringBuilder(); sb.Append ...