随笔分类 -  图论——连通性

摘要:题目链接:http://codeforces.com/problemset/problem/402/E/**算法分析: 这道题考察了图论基本知识,就是传递闭包,可以构图用强联通分量来判断*/#include#define MAXN 2005#define PI acos(-1.0)#define REP(i,n) for(int i=0; i>>">>" s;bool vis[MAXN];int n;void dfs(int u){ vis[u] = true; FOR(i,1,n) if(G[u][i] && !vis[i]) df 阅读全文
posted @ 2014-03-21 19:53 等待最好的两个人 阅读(317) 评论(0) 推荐(0)
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738题目大意:给一些点,用一些边把这些点相连,每一条边上有一个权值。现在要你破坏任意一个边(要付出相应边权值的代价),使得至少有两个连通块。输出最小代价值。算法思路:这题坑多,要考虑仔细:1.图是边双连通图,就做不到删除一边得到两个连通块,这种情况输出-1. 2.图是连通但不边双联通,就用tarjan找出桥中权值最小的,这里有个巨坑,如果桥最小的权值为0,这时根据题意,要输出1而不是0(看看题就能理解)。3.图不是连通的,就不需要去删边,即直接输出0。4.还要注意,输入的边有可能出现重边,这个要. 阅读全文
posted @ 2013-09-20 12:24 等待最好的两个人 阅读(284) 评论(0) 推荐(0)
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1300边双连通分量首先dfs找出桥并标记,然后dfs交叉着色找奇圈上的点。这题只要求在奇圈上的点个数。容易得到,一个边双联通分量如果存在奇圈,那么整个分量上的点都属于某个奇圈。#include#include#include#include#include#include#includeusing namespace std;const int maxn = 11150;const int maxe = 30100;const int INF = 0x3f3f3f;int pre[m 阅读全文
posted @ 2013-08-18 19:37 等待最好的两个人 阅读(220) 评论(0) 推荐(0)
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1291#include#include#include#include#include#include#includeusing namespace std;const int maxn = 11150;const int INF = 0x3f3f3f;int pre[maxn],low[maxn],dfs_clock;int bccnum[maxn],bcc_cnt; //记录每个点属于哪个边联通分量;bool isbridge[maxn*5]; //isbridge[i... 阅读全文
posted @ 2013-08-18 11:23 等待最好的两个人 阅读(206) 评论(0) 推荐(0)
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1063#include#include#include#include#include#include#includeusing namespace std;const int maxn = 10050;const int INF = 0x3f3f3f;vector G[maxn];int pre[maxn],low[maxn],dfs_clock;bool iscut[maxn];int ans;int n,m;void tarjan(int u,int fa){ pre[u... 阅读全文
posted @ 2013-08-17 22:59 等待最好的两个人 阅读(167) 评论(0) 推荐(0)
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1026#include#include#include#include#include#include#includeusing namespace std;const int maxn = 10050;const int INF = 0x3f3f3f;vector G[maxn];int pre[maxn],dfs_clock,low[maxn];struct ANS{ int l,r; bool operator pre[u]){ ans... 阅读全文
posted @ 2013-08-17 22:14 等待最好的两个人 阅读(178) 评论(0) 推荐(0)
摘要:题目链接:http://poj.org/problem?id=1236#include #include #include #include #include #include #include #define maxn 105#define INF 0x3f3f3fusing namespace std;bool G1[maxn][maxn],G2[maxn][maxn];vector s;int vis[maxn],sccnum[maxn],scc_cnt;int N;int in[maxn],out[maxn];/* void dfs(int u){ vis[u] = true;... 阅读全文
posted @ 2013-08-02 01:00 等待最好的两个人 阅读(158) 评论(0) 推荐(0)