UVA- 796

/**
题意:给出一个图,然后看此图的存在的桥,并且输出是哪一个,
做法:Tarjan(不存在重边)
**/
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define maxn 11000
#define maxm 100010
#define INF 0x3f3f3f3f
struct Edge
{
int to;
int next;
bool cut;
} edge[maxm];
int head[maxn],tot;
int Low[maxn],DFN[maxn],Stack[maxn];
int Index,top;
bool Instack[maxn];
bool cut[maxn];
int add_block[maxn];
int bridge;
void addedge(int u,int v)
{
edge[tot].to = v;
edge[tot].next = head[u];
edge[tot].cut = false;
head[u] = tot++;
}
void Tarjan(int u,int pre)
{
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
int son = ;
for(int i=head[u]; i != -; i = edge[i].next)
{
v = edge[i].to;
if(v == pre)
{
continue;
}
if(!DFN[v])
{
son++;
Tarjan(v,u);
if(Low[u] > Low[v]) Low[u] = Low[v];
///桥
if(Low[v]>DFN[u])
{
bridge++;
edge[i].cut = true;
edge[i^].cut = true;
}
///割点
if(u!=pre && Low[v] >= DFN[u])
{
cut[u] = true;
add_block[u] ++;
}
}
else if(Low[u] > DFN[v])
{
Low[u] = DFN[v];
}
}
if(u == pre && son>) cut[u] = true;
if(u == pre)add_block[u] = son -;
Instack[u] = false;
top--;
}
void solve(int N)
{
memset(DFN,,sizeof(DFN));
memset(Instack,false,sizeof(Instack));
memset(add_block,,sizeof(add_block));
memset(cut,false,sizeof(cut));
Index = top = ;
bridge = ;
for(int i=; i<=N; i++)
{
if(!DFN[i]) Tarjan(i,i);
}
printf("%d critical links\n",bridge);
vector<pair <int,int> > ans;
for(int u = ;u<=N;u++)
{
for(int i=head[u];i != -;i = edge[i].next)
{
if(edge[i].cut && edge[i].to > u)
{
ans.push_back(make_pair(u,edge[i].to));
}
}
}
sort(ans.begin(),ans.end());
for(int i=;i<ans.size();i++)
{
printf("%d - %d\n",ans[i].first - ,ans[i].second -);
}
printf("\n");
}
void Init()
{
tot = ;
memset(head,-,sizeof(head));
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int n;
while(~scanf("%d",&n))
{
int u,Q,v;
Init();
for(int i=;i<=n;i++)
{
scanf("%d (%d)",&u,&Q);
u++;
while(Q--)
{
scanf("%d",&v);
v++;
if(v<=u) continue;
addedge(u,v);
addedge(v,u);
}
}
solve(n); }
return ;
}

UVA - 796的更多相关文章

  1. Uva 796 Critical Links (割边+排序)

    题目链接: Uva 796 Critical Links 题目描述: 题目中给出一个有可能不连通的无向图,求出这个图的桥,并且把桥按照起点升序输出(还有啊,还有啊,每个桥的起点要比终点靠前啊),这个题 ...

  2. uva 796 Critical Links(无向图求桥)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. (连通图 模板题 无向图求桥)Critical Links -- UVA -- 796

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. UVA 796 Critical Links(Tarjan求桥)

    题目是PDF就没截图了 这题似乎没有重边,若有重边的话这两点任意一条边都不是桥,跟求割点类似的原理 代码: #include <stdio.h> #include <bits/std ...

  5. UVA 796 - Critical Links (求桥)

    Critical Links  In a computer network a link L, which interconnects two servers, is considered criti ...

  6. Uva 796 Critical Links 找桥

    这个题很简单,但是输入有毒,用字符串的我一直RE 然后换成这样瞬间AC #include <stdio.h> #include <string.h> #include < ...

  7. UVA 796 Critical Links(无向图求桥)

    题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号  (与这个点相连的点的个数m)  依次是m个点的   输入到文件结束. 桥输出的时候需要排序   知识汇总: 桥:   无向连通 ...

  8. C - Critical Links - uva 796(求桥)

    题意:有一些网络通过一些线路连接,求关键的连接,也就是桥,如果删除这个链接那么会产生两个子树 分析:注意一下图不是连通图即可 ************************************* ...

  9. UVA 796 Critical Links

    输出桥. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  10. UVA 796 Critical Links (tarjan算法求割边)

    这是在kuangbin的题目里看到的,不得不吐槽一下,题目中居然没给出数据范围,还是我自己猜的-本来是一道挺裸的题,但是我wa了好多次,原因就是这里面有两个坑点,1重边特判,2输出时左边必须比右边小. ...

随机推荐

  1. [Leetcode] longest valid parentheses 最长的有效括号

    Given a string containing just the characters'('and')', find the length of the longest valid (well-f ...

  2. [学习笔记]Segment Tree Beats!九老师线段树

    对于这样一类问题: 区间取min,区间求和. N<=100000 要求O(nlogn)级别的算法 直观体会一下,区间取min,还要维护区间和 增加的长度很不好求.... 然鹅, 从前有一个来自杭 ...

  3. Linux安装cx_Oracle

    安装依赖包 yum -y install gcc python-devel 确认以下变量都已经设置好了 export ORACLE_HOME=/home/oracle/app/oracle/produ ...

  4. VS 2013 with update安装失败(kb2829760)解决方案

    update过程中遇到kb2829760补丁无法更新而导致vs安装失败的解决方法: 1.安装KB2829760: 2.安装KB2829760中文语言包: 3.安装VS2013 with update. ...

  5. Moodle插件开发——Blocks(版块)

    前提: 1)     基于Moodle3.0,要求Moodle版本高于2.0 2)     PHP编程基础:语言的了解和开发工具使用 有经验的开发人员和那些只是想程序员的参考文本应参阅附录A. 1.  ...

  6. each jquery

    <div class="first"> <span>投保人数:</span> <input type="text" i ...

  7. 理解JavaScript的prototype和__proto__

    首先,要明确几个点: 1.在JS里,万物皆对象. 方法(Function)是对象,方法的原型(Function.prototype)是对象.因此,它们都会具有对象共有的特点.即:对象具有属性__pro ...

  8. Spring structs2 hibernate 整合(ssh)

    ssh项目jar包 项目内容: 1. 加入 Spring 1). 加入 jar 包2). 配置 web.xml 文件3). 加入 Spring 的配置文件.(application.xml) 2. 加 ...

  9. [Luogu 2805] NOI2009 植物大战僵尸

    这题是个比较经典的最大权闭合子图,可以建图转化为最小割问题,再根据最大流最小割定理,采用任意一种最大流算法求得. 对于每个点,如果点权w为正,则从源点到这个点连一条边权为w的有向边:否则如果w为负则从 ...

  10. iOS 隐藏/显示导航栏

    一.隐藏导航栏 [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBa ...