pid=2586 题意:给一棵树,询问u和v之间的边权和。 AI检测代码解析 #pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <string.h> #include <stdio.h> #include <vector> using namespace std; const int N = 50005; vector<int> v[N],w[N],query[N],num[N];...
hdu2586(最近公共祖先-两种方法实现) 这道题题意是,给定一棵树,每条边都有一定的权值,q次询问,每次询问某两点间的距离。这样就可以用LCA来解,首先找到u, v 两点的lca,然后计算一下距离值就可以了。这里的计算方法是,记下根结点到任意一点的距离dis[],这样ans = dis[u] + dis[v] - 2 * dis[lca(v,...
intquery(intx,inty){while(top[x]!=top[y]){if(rank1[top[x]]<=rank1[top[y]])y=p[top[y]];elsex=p[top[x]];}if(rank1[x]<=rank1[y])returnx;returny;}llans(intx,inty){ll m1=dis[x],m2=dis[y];intlca=query(x,y);returnm1+m2-2*dis[lca];}};intmain(){intT;scanf("...
(显然,这次不太容易打暴力咧) (但听说还是有大佬用dfs直接a掉了) 正好 趁这个机会复习一下LCA 这里用的是倍增lca 的思想(一不小心是会写tle的吧) (也有可能是因为我太弱了才t掉的) 我才不会说我有一次卑微了 一开始看PPT 以为自己明白了 结果发现 有一点点问题 由于本题中这个树是题里给的 所以节点的...
2586How far away? 2874Connections between cities 3486Interviewe 2888Check Corners 【矩阵乘法】 1575Tr A 1757A Simple Math Problem 2254奥运 2256Problem of Precision 1558Gauss Fibonacci 2604Queuing 2276Kiki & Little Kiki 2 2855Fibonacci Check-up 2971Tower 2294Pendant 3117Fibonacci Numbers 2842Chinese Rin...
hdu---(2586)How far away ?(DFS/LCA/RMQ) 编程算法 How far away ? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5492 Accepted Submission(s): 2090 Problem Description There are n houses in the village and some bidirectional roads...
大数 ●●● ●●● ●●● ● ●●● 10461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092 ●●● ●● ●●● ●●● ●●● 10931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111...
111关注 2粉丝 2586微博 微关系 她的关注(56) 钟辰乐 软糖王国小仓库 大脸猫爱吃鱼cat insomnia_chenle 她的粉丝(2) 泡澡椰OoO 新手指南 查看更多 a 相册 查看更多a 微博精彩 热门微博热门话题 微博会员微相册 微游戏微指数 手机玩微博 扫码下载,更多版本戳这里 认证&合作 申请认证链接网站...
2166、 1562、 2705、 3664、 1260、 2752、 3183、 2350、 1975、 1331、 1287、 3331、 1693、 1389、 1488、 2316、 1929、 2960、 1721、 1459、 2082、 1564、 2248、 3191、 2263、 2282、 1313、 1543、 2407、 1468、 2389、 3208、 1629、 2126、 1105、 3224、 1580、 3456、 2586、 1129...
大数 ●●● ●●● ●●● ● ●●● 10461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092 ●●● ●● ●●● ●●● ●●● 10931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111...