先做最小生成树,这样就保证了最大值最小 然后随便用个什么东西维护一下最大值,我用的树剖log^2,倍增会更快 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=100005; int n,m,k,f[N],h[N],cnt,va[N],de[N],fa[N],si[N],hs[N],fr[N],id[N],rl[N],tot; struct q…
模板题,练练手~ Code: #include <cstdio> #include <algorithm> #define N 80000 #define setIO(s) freopen(s".in","r",stdin) using namespace std; namespace tree { int hd[N],to[N],nex[N],edges; int fa[N],top[N],siz[N],dep[N],son[N]; voi…
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5723 Abandoned country Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 7573 Accepted Submission(s): 1850 Problem Description An abandoned country…
对于每个节点维护这个节点到根的权值线段树 对于每个询问(x,y),这条路径上的线段树 tree[x]+tree[y]-tree[lca(x,y)]-tree[fa[lca(x,y)]] #include<cstdio> #include<algorithm> using namespace std; ; ; int n,m,tot,cnt,ind,sz,last; int tmp[maxn],hash[maxn],g[maxn],v[maxn]; int num[maxn],pos…