codeforces 659E . New Reform 强连通】的更多相关文章

题目链接 对于每一个联通块, 如果有一个强连通分量, 那么这个联通块对答案的贡献就是0. 否则对答案贡献是1. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <complex> #include <cmath> #include <map> #inc…
题意:给你一个无向图,如今要求你把边改成有向的. 使得入度为0的点最少,输出有多少个点入度为0 思路:脑补一波结论.假设有环的话显然没有点入度为0,其余则至少有一个点入度为0,然后就DFS一波就能够了 #include <cstdio> #include <queue> #include <cstring> #include <iostream> #include <cstdlib> #include <algorithm> #inc…
题目链接: http://codeforces.com/problemset/problem/659/E 题意: 给定n个点和m条双向边,将双向边改为单向边,问无法到达的顶点最少有多少个? 分析: 无法到达的话即入度为0. DFS判断每一个连通块中是否存在环,如果存在环,就能保证环中每个点的入度都大于等于1.否则,有头有尾,头的入度为0. 代码: #include<cstdio> #include<queue> #include<cstring> #include<…
Description Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It isnot guaranteed that you can get from any city to any other one, using only the…
New Reform time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected b…
题目链接: E. New Reform time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is co…
题目链接:http://codeforces.com/problemset/problem/732/F 题意: 给出一个有n个点m条边的无向图,保证联通,现在要求将所有边给定一个方向使其变成有向图,设f(x)为点x能到达的点的个数,要求使最小的f(x)最大,并输出方案. 思路: tarjan一下,答案肯定是强连通分量里点最多的一个分量,而同一个强连通里的点成环,其他分量都指向这个最大点个数的分量. 退役了,偶尔刷一下题... #include <bits/stdc++.h> using nam…
<题目链接> 题目大意: 有n个房间,每个房间都会有一只老鼠.处于第i个房间的老鼠可以逃窜到第ai个房间中.现在要清理掉所有的老鼠,而在第i个房间中防止老鼠夹的花费是ci,问你消灭掉所有老鼠的最少花费. 解题分析: 首先就是要注意老鼠的逃生路线为强连通分量的情况,毫无疑问,这种情况就是在那个强连通分量中的代价最小的房间安装老鼠夹(因为根据老鼠的流通性,只需要在连通分量中安装一个老鼠夹就能捕获所有的老鼠),所以我们先用Tarjan对这些房间进行缩点.然后我们只需要将那些出度为0的强连通分量的代价…
边双连通分量. 这题有一点构造的味道.一个有向图,经过强连通缩点之后会形成一个有向无环图. 如果将最大的强连通分量放在顶端,其余的强连通分量都直接或间接指向他,那么这样就构造出了符合要求的图. 接下来就是要去寻找强连通分量.对于一个无向图来说,每一个边-双联通分量都可以将每条边定向之后构造成一个强连通分量,$dfs$一遍即可. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #…
构造. 有一种十分巧妙的方法可以使图中所有度数为偶数的节点,经过每条边定向后,出度和入度都相等. 首先统计每个节点的度数,将度数为奇数的节点与编号为$n+1$的节点连边,这样一来,这张新图变成了每个节点的度数都是偶数的图,必然存在欧拉回路.任意一条欧拉回路都使得原图中度数为偶数的节点的出度与入度相等. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cs…