Because of the financial crisis, a large number of enterprises go bankrupt. In addition to this, other enterprises, which have trade relation with the bankrup enterprises, are also faced with closing down. Owing to the market collapse, profit decline and funding chain intense, the debt-ridden entrepreneurs 
have to turn to the enterprise with stably developing for help. 

Nowadays, there exist a complex net of financial trade relationship between enterprises. So if one of enterprises on the same financial chain is faced with bankrupt, leading to cashflow's obstruction, the other enterprises related with it will be influenced as well. At the moment, the foresight entrepreneurs are expected the safer cooperation between enterprises. In this sense, they want to know how many financial chains between some pairs of enterprises are independent with each other. The indepence is defined that if there exist two roads which are made up of enterprises(Vertexs) and their financial trade relations(Edge) has the common start point S and end point T, and expect S and T, none of other enterprise in two chains is included in these two roads at the same time. So that if one of enterpirse bankrupt in one of road, the other will not be obstructed.

Now there are N enterprises, and have M pair of financial trade relations between them, the relations are Mutual. They need to ask about Q pairs of enterprises' safety situations. When two enterprises have two or more independent financial chains, we say they are safe enough, you needn't provide exact answers.

InputThe Input consists of multiple test cases. The first line of each test case contains three integers, N ( 3 <= N <= 5000 ), M ( 0 <= M <= 10000 ) and Q ( 1 <= Q <= 1000 ). which are the number of enterprises, the number of the financial trade relations and the number of queries. 
The next M lines, each line contains two integers, u, v ( 0 <= u, v < N && u != v ), which means enterpirse u and enterprise v have trade relations, you can assume that the input will not has parallel edge. 
The next Q lines, each line contains two integers, u, v ( 0 <= u, v < N && u != v ), which means entrepreneurs will ask you the financial safety of enterpirse u and enterprise v. 
The last test case is followed by three zeros on a single line, which means the end of the input.OutputFor each case, output the test case number formated as sample output. Then for each query, output "zero" if there is no independent financial chains between those two enterprises, output "one" if there is only one such chains, or output "two or more".Sample Input

3 1 2
0 1
0 2
1 0
4 4 2
0 1
0 2
1 2
2 3
1 2
1 3
0 0 0

Sample Output

Case 1:
zero
one
Case 2:
two or more
one

题意:

给你一个(保证输入无重边,无自环)无向图,然后有下面Q条询问,每条询问为:问你u点与v点之间有几条(除了首尾两点外,其他点不重复)的路径.如果有0条或1条输出0或1,如果有2条以上,输出”two or more”.

分析:

首先如果u点与v点不连通,直接输出0即可.(用并查集实现)

然后如果u点与v点属于同一个点-双连通分量,输出two or more.(这里有特例,两点一边的点-双连通分量应该输出1)

自己写的代码已知wrong不知道为什么,哪位大佬看一看谢谢。。

 #include<cstring>
#include<cmath>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std; int n,m,q,TAK,col,tim,top,tot;
int a[],color[],dfn[],low[],stack[],ins[];
int cnt,head[],Next[],rea[];
struct Node
{
int x,y;
}b[];
map<int,int>p; void add(int u,int v)
{
Next[++cnt]=head[u];
head[u]=cnt;
rea[cnt]=v;
}
void Tarjan(int u,int fa)
{
int num=;color[u]=col;
dfn[u]=low[u]=++tim;
stack[++top]=u,ins[u]=;
for (int i=head[u];i!=-;i=Next[i])
{
int v=rea[i];
if (v==fa) continue;
if (!dfn[v])
{
Tarjan(v,u);num++;
low[u]=min(low[u],low[v]);
if (low[v]>=dfn[u])
{
tot=;
int x=-;
while(x!=u)
{
x=stack[top--];
ins[x]=;
a[++tot]=x;
}
stack[++top]=u,ins[u]=;
if (tot==) continue;
for (int j=;j<tot;j++)
for (int k=j+;k<=tot;k++)
{
int x=a[j],y=a[k];
if (x>y) swap(x,y);
if (p[x*n+y]==-) p[x*n+y]=;
}
}
}
else low[u]=min(low[u],dfn[v]);
}
}
int main()
{
while(~scanf("%d%d%d",&n,&m,&q)&&(n+m+q))
{
printf("Case %d:\n",++TAK);
cnt=top=tim=;p.clear();
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(color,,sizeof(color));
memset(head,-,sizeof(head));
for (int i=,x,y;i<=m;i++)
{
scanf("%d%d",&x,&y);
x++,y++;
add(x,y),add(y,x);
}
for (int i=;i<=q;i++)
{
scanf("%d%d",&b[i].x,&b[i].y);
b[i].x++,b[i].y++;
if (b[i].x>b[i].y) swap(b[i].x,b[i].y);
p[b[i].x*n+b[i].y]=-;
}
for (int i=;i<=n;i++)
if (!dfn[i])
{
col=i;
Tarjan(i,-);
}
for (int i=;i<=q;i++)
if (color[b[i].x]!=color[b[i].y]) printf("zero\n");
else if (p[b[i].x*n+b[i].y]==-) printf("one\n");
else printf("two or more\n");
}
}

HDU 3749 Financial Crisis(点-双连通分量)的更多相关文章

  1. HDU 3749 Financial Crisis (点双连通+并查集)

    <题目连接> 题目大意: 给你一个(保证输入无重边,无自环)无向图,然后有下面Q条询问,每条询问为:问你u点与v点之间有几条(除了首尾两点外,其他点不重复)的路径.如果有0条或1条输出0或 ...

  2. HDU 3749 Financial Crisis 经济危机(点双连通分量)

    题意: 给一个图n个点m条边(不一定连通),接下来又q个询问,询问两个点是为“不相连”,“仅有一条路径可达”,“有两条及以上的不同路径可达”三种情况中的哪一种.注:两条以上的路径指的是路径上的点连1个 ...

  3. HDU 3749 Financial Crisis

    Financial Crisis 题意:给一个图,包含N ( 3 <= N <= 5000 )个点, M ( 0 <= M <= 10000 )条边 and Q ( 1 < ...

  4. hdu 2460(tarjan求边双连通分量+LCA)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2460 思路:题目的意思是要求在原图中加边后桥的数量,首先我们可以通过Tarjan求边双连通分量,对于边 ...

  5. HDU 4612 Warm up (边双连通分量+DP最长链)

    [题意]给定一个无向图,问在允许加一条边的情况下,最少的桥的个数 [思路]对图做一遍Tarjan找出桥,把双连通分量缩成一个点,这样原图就成了一棵树,树的每条边都是桥.然后在树中求最长链,这样在两端点 ...

  6. HDU 4612 Warm up (边双连通分量+缩点+树的直径)

    <题目链接> 题目大意:给出一个连通图,问你在这个连通图上加一条边,使该连通图的桥的数量最小,输出最少的桥的数量. 解题分析: 首先,通过Tarjan缩点,将该图缩成一颗树,树上的每个节点 ...

  7. 2013杭州网赛 1001 hdu 4738 Caocao's Bridges(双连通分量割边/桥)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 题意:有n座岛和m条桥,每条桥上有w个兵守着,现在要派不少于守桥的士兵数的人去炸桥,只能炸一条桥 ...

  8. HDU 4612 Warm up(双连通分量缩点+求树的直径)

    思路:强连通分量缩点,建立一颗新的树,然后求树的最长直径,然后加上一条边能够去掉的桥数,就是直径的长度. 树的直径长度的求法:两次bfs可以求,第一次随便找一个点u,然后进行bfs搜到的最后一个点v, ...

  9. HDU 5458 Stability(双连通分量+LCA+并查集+树状数组)(2015 ACM/ICPC Asia Regional Shenyang Online)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5458 Problem Description Given an undirected connecte ...

随机推荐

  1. Xcode配置SVN详细步骤

    转载:http://blog.csdn.net/weiqubo/article/details/8288635   Xcode 默认自带Git 与 SVN,我们本篇介绍SVN的详细配置步骤如下: 1. ...

  2. ReactJS-3-组件生命周期

    简介 普通的UI应用生命周期一般包括Birth, Growth, Death, React中Component的生命周期也是如此,这是一个持续的过程,贯穿整个应用的生命历程. 阶段 1.mountin ...

  3. spring 整合struts

    1.例子:未被spring整合 struts.xml 的配置文件 <constant name="struts.enable.DynamicMethodInvocation" ...

  4. 解决重置PostgreSQL 9.6密码的问题

    一.PostgreSql9.6重置密码的方法: 1.打开windows服务管理器,找到“postgresql-x64-9.6”服务,停止服务. 2.找到PostgreSQL9.6的安装目录(以我的E盘 ...

  5. 【经验分享】IMX6开发板编译问题及解决方法

    本文转自迅为IMX6开发板售后讨论群,分享给大家~物理主机 win10 64 位专业版.虚拟机 VM12 Pro.开发环境采用迅为提供的开发环境:Ubuntu12.04.2 .镜像采用最新的:iTOP ...

  6. 解决android的键盘弹出时,html页面的高度被压缩

    如果元素的高度是用100%表示,那么,安卓的键盘弹出时,高度会发生变化,导致布局混乱,所以最好给高度设置像素高度 $("html,body").height(window.inne ...

  7. 哈尔滨工程大学ACM预热赛 补题

    链接:https://ac.nowcoder.com/acm/contest/554/A来源:牛客网 小虎刚刚上了幼儿园,老师让他做一个家庭作业:首先画3个格子,第二行有2个格子,第三行有1个格子. ...

  8. 防止asp.net连续点击按钮重复提交

    1.在Page_Load中添加如下代码: protected void Page_Load(object sender, EventArgs e) { this.btnEdit.Attributes[ ...

  9. 除了上万的月薪之外,还有什么理由让我们必须学Python?

    虽然目前的编程语言有很多,但是基础语法上的概念,本质上都是相通的.可以做到一通百通.所以没有必要为了学哪门语言纠结太多. python是目前市面上,我个人认为是最简洁&&最优雅& ...

  10. No-7.运算符

    数学符号表链接:https://zh.wikipedia.org/wiki/数学符号表 01. 算数运算符 是完成基本的算术运算使用的符号,用来处理四则运算 运算符 描述 实例 + 加 10 + 20 ...