@codeforces - 1149D@ Abandoning Roads】的更多相关文章

目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 n 点 m 条边的无向连通图,每条边的边权为 a 或 b. 对于 1 ~ n 中的每一个 i,求在所有可能的最小生成树中 1 -> i 的最短路的最小值. Input 第一行包含 4 个整数 n, m, a 与 b (2≤n≤70, n−1≤m≤200, 1≤a<b≤10^7) 接下来 m 行,每行三个整数 u, v, c (1≤u,v≤n, u≠v…
\(>Codeforces\space835 F. Roads in the Kingdom<\) 题目大意 : 给你一棵 \(n\) 个点构成的树基环树,你需要删掉一条环边,使其变成一颗树,并最小化删掉环边后的树的直径. \(n \leq 2 \times 10^5\) 树的边权 $ \leq 10^9 $ 解题思路 : 考虑最终树的直径可能由两部分组成,答案是其中的最大值 第一种就是外向树内的直径的最大值,这个只需要随便\(dp\)一下即可,这里不过多讨论 第二种情况树的直径经过原来的环,…
大意: 给定无向图, 边权只有两种, 对于每个点$x$, 输出所有最小生成树中, 点$1$到$x$的最短距离. 先将边权为$a$的边合并, 考虑添加边权为$b$的边. 每条路径只能经过每个连通块一次, 直接状压的话有$O(n2^n)$个状态. 但是注意到点数不超过$3$的连通块内部最短路不超过$2a$, 所以求最短路时一定只经过$1$次, 所以可以不考虑. 这样总状态就为$O(n2^{\frac{n}{4}})$. #include <iostream> #include <iostre…
这道题并不简单,要得出几个结论之后才可以做.首先就是根据Kruskal求最小生成树的过程,短边是首选的,那么对于这道题也是,我们先做一次直选短边的最小生成树这样会形成多个联通块,这些联通块内部由短边相连.那么接下来要形成完整的最小生成树,我们就得用长边把这些联通块连起来,因为要最短路径,所以我们用Dijkstra做连边的过程 这里给出一个结论:只要满足两个条件:第一,每个联通块内部不能连长边.第二,一个联通块不能被访问两遍. 重点来了:只要是满足这两个条件下树就能保证它是一棵最小生成树. 为什么…
ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of n towns numbered from1 to n. There are n directed roads in the Udayland. i-th of them goes from town i to some other town ai (ai ≠ i). ZS th…
题目链接:http://codeforces.com/problemset/problem/711/D 思路:由于每个点出度都为1,所以没有复杂的环中带环.DFS遍历,若为环则有2^k-2种,若为链则为2^k种. #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+10; const int mod=1e9+7; int v[N],vis[N],num,times[N],c[N];…
题目链接: http://codeforces.com/problemset/problem/711/D 题目大意: 给一张N个点N条有向边的图,边可以逆向.问任意逆向若干条边使得这张图无环的方案数(mod 1e9+7). 题目思路: [图论] 因为是N条边所以不会有复杂的环,最多只会有若干组一个环加一条链. 推算得到,一个大小为k的环对答案的贡献是*(2k-2),而长度为k的链对答案的贡献是2k(链不包括环上的) 用dfs找出每一组环的大小和链的长度,计算答案即可. // //by coolx…
Description There are n cities in Berland, each of them has a unique id - an integer from 1 to n, the capital is the one with id 1. Now there is a serious problem in Berland with roads - there are no roads. That is why there was a decision to build n…
题目描述 Mayor of Yusland just won the lottery and decided to spent money on something good for town. For example, repair all the roads in the town. Yusland consists of n intersections connected by n - 1 bidirectional roads. One can travel from any inter…
F. Roads in the Kingdom(树形dp) 题意: 给一张n个点n条边的无向带权图 定义不便利度为所有点对最短距离中的最大值 求出删一条边之后,保证图还连通时不便利度的最小值 $n <= 2e5 $ \(w_i <= 1e9\) 思路:树形dp 这个图是一个环上挂着很多颗树,首先把这个环处理出来, 删边只能在环上进行,所以可以先求出以环上每个点为根的树的直径和最大深度dep, 答案来源分为二种 树内部两点最远距离 -> 直径 (树形dp 或者 两次bfs) 两棵树深度最大…