https://www.luogu.org/problem/show?pid=2934 题目描述 Gremlins have infested the farm. These nasty, ugly fairy-like creatures thwart the cows as each one walks from the barn (conveniently located at pasture_1) to the other fields, with cow_i traveling to…
题链: https://www.luogu.org/problemnew/show/P2934 题解: 最短路(树),可并堆(左偏堆),并查集. 个人感觉很好的一个题. 由于题目已经明确说明:从1点到每个点的最短路有且只有一条. 那么跑完最短路后,就可以得到一个最短路树,即每个点只有一个来源点. 然后来考虑,如果某一个u点无法从其最短路树上的father到达时,是个怎样的情况: 由于u无法从其父亲到达,所以如果还存在1到u的路径的话, 应该在其子树内(包括u),存在一个v点,与子树外的某个节点x…
题目链接 luogu P2934 [USACO09JAN]安全出行Safe Travel 题解 对于不在最短路树上的边(x, y) 1 | | t / \ / \ x-----y 考虑这样一种形态的图, '-' 标记为非最短路树的边 对于边集(x, t)内的任意一点 i, 到达它的所有方式一定是 1 -> t -> y -> x -> i 这样就可以对树边(x, t)标记 Min = dis[y] + dis[x] + W_{x,y} 每个点在标记中取最小 Answer_i 就是…
P2934 [USACO09JAN]安全出行Safe Travel https://www.luogu.org/problemnew/show/P2934 分析: 建出最短路树,然后考虑一条非树边u,v,w,它可以让u->lca的路径上的点x的答案更新为dis[v]+dis[u]+w-dis[x].为从1走到v(dis[v]),从v走到u(+w),从u走到x,(dis[u]-dis[x]). 然后对于每条非树边,按照dis[v]+dis[u]+w排序,然后会发现每个点只会更新一次,然后用并查集维…
题目描述 Gremlins have infested the farm. These nasty, ugly fairy-like creatures thwart the cows as each one walks from the barn (conveniently located at pasture_1) to the other fields, with cow_i traveling to from pasture_1 to pasture_i. Each gremlin is…
原题地址 题目描述 Gremlins have infested the farm. These nasty, ugly fairy-like creatures thwart the cows as each one walks from the barn (conveniently located at pasture_1) to the other fields, with cow_i traveling to from pasture_1 to pasture_i. Each greml…
题目 什么神仙题啊,我怎么只会\(dsu\)啊 我们考虑一个非常暴力的操作,我们利用\(dsu\ on \ tree\)把一棵子树内部的非树边都搞出来,用一个堆来存储 我们从堆顶开始暴力所有的边,如果这条边指向的另外一个点不在当前子树里,我们就把这条边计入答案 这样复杂度显然不是很对,因为我们每次可能要把子树里的边全都访问上一次 考虑让这个暴力的复杂度科学一点 我们发现,如果有一条边在当前这个节点不合法,也就是指向了一个子树内部的边,非常显然,这个点在更往上的点里也会不合法,所以我们直接在这里把…
P2935 [USACO09JAN]最好的地方Best Spot 题目描述 Bessie, always wishing to optimize her life, has realized that she really enjoys visiting F (1 <= F <= P) favorite pastures F_i of the P (1 <= P <= 500; 1 <= F_i <= P) total pastures (conveniently nu…
P2936 [USACO09JAN]全流Total Flow 题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 <= N <= 700) water pipes on the farm that connect the well to the barn. He was surprised to find a wild mess of different…
题目描述 Bessie, always wishing to optimize her life, has realized that she really enjoys visiting F (1 <= F <= P) favorite pastures F_i of the P (1 <= P <= 500; 1 <= F_i <= P) total pastures (conveniently numbered 1..P) that compose Farmer…