【倍增LCA】 NOIP2013 T3货车运输 - cool's Blog
【倍增LCA】 NOIP2013 T3货车运输
cool
posted @ 2015年9月13日 20:39
in 数据结构
, 414 阅读
人生第一道A掉的提高组T3= =
倍增+LCA 就能轻松AC了
但lbn大神让我去学树剖LCA 而我连树剖都不会 结果被大D一通
void Mul() { for (int i = 1;i <= 14;i++) //14是logn for (int j = 1;j <= n;j++) if (p[j][i-1] != -1) { p[j][i] = p[p[j][i-1]][i-1]; dis[j][i] = min(dis[j][i-1],dis[p[j][i-1]][i-1]);//距离 } }
int LCA(int a,int b) { if (deep[a] < deep[b]) swap(a,b); int mina = 100000000,minb = 100000000; int t = deep[a] - deep[b]; for (int i = 0;i <= 14;i++) if (t&(1 << i)) mina = min(mina,dis[a][i]),a = p[a][i];//到同一层 if (a == b) return mina; for (int i = 14;i >= 0;i--) if (p[a][i] != -1&& p[a][i] != p[b][i]) { mina = min(mina,dis[a][i]); a = p[a][i]; minb = min(minb,dis[b][i]); b = p[b][i]; } if (a == b) return min(mina,minb); return min(min(mina,dis[a][0]),min(minb,dis[b][0])); }
2015年9月18日 13:24
这题并不能树剖LCA。。这题必须要维护出路上的最大值啊,还是倍增方便
2015年10月03日 18:53
@orz hhw: 线段树维护树链
2015年10月17日 20:17
@Flandre Scarlet: 多麻烦。。剖完还要写线段树,倍增可以直接维护
2015年10月18日 13:49
@hhw: 蛤蛤
2022年8月22日 03:48
11th Important Question Paper for HP Board 2023, This year's HPBOSE Class Xllth Exams were held by the Himachal Pradesh Board of School Education. upon the satisfactory completion of the exam. The HPBOSE +1 Question Paper 2023 for the HPBOSE Class 11th Exam will be released shortly, most likely in the months of May or June. They are all anxiously awaiting the release of the HP Board 11th Question Paper 2023 online. HP 11th Model Paper 2023 The HP Board will release the HPBOSE Class 11th test Question Paper 2023 in the month of May on the same official web portal site at, according to the official notice. Students looking for the 2023 HPBOSE 11th class Question Paper.