泡泡浴の在家:一场属于自己的奢华放松

核心内容摘要

当灵感触角延伸至云端:“阿阿阿飞天了”——一场关于自由与创意的奇幻之旅
《藏在月色下的多巴胺:这份深夜私享观影指南,建议成年人低调收藏》

穿越时光的浪漫回响:李蓉蓉艾熙三部曲,你心中的经典是哪一部?

F. Unique Occurrencestime limit per test: 6 secondsmemory limit per test: 1024 megabytesinput: standard inputoutput: standard outputYou are given a tree, consisting ofnnnvertices. Each edge has an integer value written on it.Letf(v,u)f(v, u)f(v,u)be the number of values that appearexactly onceon the edges of a simple path between verticesvvvanduuu.Calculate the sum off(v,u)f(v, u)f(v,u)over all pairs of verticesvvvanduuusuch that1≤vu≤n1 \le v u \le n1≤vu≤n.DeepL 翻译:给你一棵由nnn个顶点组成的树。

每条边上都写有一个整数值。

假设f(v,u)f(v,u)f(v,u)是顶点vvv和uuu之间简单路径的边上只出现一次的值的个数。

计算所有顶点vvv和uuu之间的f(v,u)f(v,u)f(v,u)和1≤vu≤n1 ≤ v u ≤ n1≤vu≤n。

把每种颜色看为时间轴上的事件进行分治处理。

简单来讲我们用线段树分治对于每种颜色全部删除后的树上的 dsu 进行统计很显然此时某一条边的贡献就是 左右两个连通块的大小的乘积然后再把这种颜色的边加回来再进行下一条边的枚举。

总的复杂度只有 n log nvectortupleint,int,inte;vectorvectorPIIcol;intans;structop{intt,a,b;};classDSU{public:vectorintf,siz;stackopsave;DSU(){}DSU(intn){init(n);}voidinit(intn){f.resize(n

;iota(range(f),

;siz.assign(n1,

;}intfind(intx){returnf[x]x?x:find(f[x]);}boolsame(intx,inty){returnfind(x)find(y);}boolmerge(intx,inty){xfind(x);yfind(y);if(xy){return0;}if(siz[x]siz[y]){swap(x,y);}save.push({1,x,y});siz[y]siz[x];f[x]y;returntrue;}voidrollback(){auto[t,x,y]save.top();save.pop();if(t

{siz[y]-siz[x];f[x]x;}else{}}size_tgetSnapshot()const{returnsave.size();}voidroll(inttar){while(save.size()tar){rollback();}}intsize(intx){returnsiz[find(x)];}};templatetypenameTclassSegmentTreeDC{public:inttot;// 时间点数叶子数量vectorvectorTtr;// 每个节点的操作列表SegmentTreeDC():tot(0LL){}SegmentTreeDC(int_T){init(_T);}voidinit(int_T){totmax(1LL,_T);tr.clear();tr.resize(4LL*(tot

);}// 插入一个操作 op 到闭区间 [l, r]voidinsert(intp,intL,intR,intl,intr,constTop){if(lr||lR||rL)return;if(lLRr){tr[p].push_back(op);return;}intmidLR1;insert(p1,L,mid,l,r,op);insert(p1|1,mid1,R,l,r,op);}voidinsert(intl,intr,constTop){if(lr)return;insert(1,1,tot,l,r,op);}voiddfs(DSUdsu){functionvoid(int,int,int)dfs[](intp,intl,intr){size_t snapdsu.getSnapshot();for(autoe:tr[p]){dsu.merge(e.first,e.second);}if(lr){for(auto[u,v]:col[l]){ansdsu.size(u)*dsu.size(v);}}else{intmid(lr)1;dfs(p1,l,mid);dfs(p1|1,mid1,r);}dsu.roll(snap);};dfs(1,1,tot);}};voidsolve(){intn;cinn;e.resize(n

;col.resize(n

;for(inti1;in;i){intu,v,w;cinuvw;e[i]{u,v,w};col[w].push_back({u,v});}DSUdsu(n);SegmentTreeDCPIIseg(n);for(inti1;in;i){auto[u,v,w]e[i];seg.insert(1,w-1,{u,v});seg.insert(w1,n,{u,v});}seg.dfs(dsu);coutansendl;}signedmain(){cin.tie(nullptr)-ios::sync_with_stdio(false);intT1;// cin T;for(;T_T;T_)solve();return0;}

满18岁免费播-满18岁免费播应用

百度百家号客服电话人工服务

123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123