【CF711D】Directed Roads】的更多相关文章

题目大意:给定一个 N 个点,N 条边的无向图,现给每条边定向,求有多少种定向方式使得定向后的有向图中无环. 题解:显然,这是一个外向树森林,定向后存在环的情况只能发生在基环树中环的位置,环分成顺时针和逆时针两种情况,其他边方向随意.因此,记外向树森林中环的大小为 \(w[i]\),则答案为\[2^{n-\sum w[i]}*\prod (2^{w[i]}-2)\] 代码如下 #include <bits/stdc++.h> #define pb push_back #define mp ma…
题意: 给一张N个点N条有向边的图,边可以逆向.问任意逆向若干条边使得这张图无环的方案数(mod 1e9+7). n<=200000 思路:三个样例给的好 找规律方便很多 易得有N点的环有(2^n)-2中改法,除了不改和都改 剩下的都是链,设除环外还有K个点,他们的总贡献就是2^k,因为都是一条边相连接怎么改也没有环 CF上快速幂要写在外面不然会出现奇奇怪怪的CE ; ..]of longint; n,tot,i,id,time,top,x,m:longint; ans,f,tmp:int64;…
[题解]Paid Roads [SP3953] [Poj3411] 传送门:\(\text{Paid}\) \(\text{Roads}\) \(\text{[SP3953]}\) \(\text{[Poj3411]}\) [题目描述] 给出一张 \(n\) 个点 \(m\) 条边的有向图.对于每条边 \((x,y)\),如果之前经过 \(z\) 点,那么费用为 \(p\),否则为 \(r\).求 \(1\) 到 \(n\) 的最小费用.如果无法到达则输出 " \(\text{impossibl…
[网络流]One-Way Roads 题目描述 In the country of Via, the cities are connected by roads that can be used in both directions. However, this has been the cause of many accidents since the lanes are not separated: The drivers frequently look at their smartphon…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of n towns numbered from 1 to n. Ther…
light1002:传送门 [题目大意] n个点m条边,给一个源点,找出源点到其他点的‘最短路’ 定义:找出每条通路中最大的cost,这些最大的cost中找出一个最小的即为‘最短路’,dijkstra变形.dis[i]为s->i的‘最短路’ #include<bits/stdc++.h> ][],dis[],vis[]; using namespace std; int n; void dij(int s) { int i,j,k; ; i<n; i++) { dis[i]=mp[…
爽爆.史上个人最快MST的记录7分40s..一次A. #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <cctype> #include <algorithm> #include <numeric> #define typec int using names…
最小生成树水题.prim一次AC #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <cctype> #include <cmath> #include <algorithm> #include <numeric> #define typec int using namespace std;…
题目链接 题目大意:问使含有$p$个节点的子树分离至少需要去掉几条边. ------------------ 设$f[i][j]$表示以$i$为根的子树保留$j$个节点所去掉的最少边数. 初始化$f[u][1]=c[u]$.$c[u]$是这个节点的度. 转移方程$f[u][j]=min(f[u][j],f[u][k]+f[v][j-k]-2)$.为什么要减$2$?这是因为我们在初始化的时候已经把连接父节点和子节点的这条边去掉了.这时候再把他们连起来,为防止重复计算,我们分别把$u->v$和$v-…
题目内容 洛谷链接 Farmer John正在一个新的销售区域对他的牛奶销售方案进行调查.他想把牛奶送到\(T\)个城镇 (\(1 <= T <= 25,000\)),编号为\(1\)到\(T\).这些城镇之间通过R条道路 (\(1 <= R <= 50,000\),编号为\(1\)到\(R\)) 和\(P\)条航线 (\(1 <= P <= 50,000\),编号为\(1\)到\(P\)) 连接.每条道路i或者航线i连接城镇\(A_i\) (\(1 <= A_i…