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. 关于tomcat一些简介

    window下,在tomcat的bin目录下,用cmd输入startup.bat 即可启动tomcat 成功启动Tomcat后,通过访问http://localhost:8080/便可以使用Tomca ...

  2. zojDakar Rally(01背包)

    01背包 加上每次更新解题数目最多 总用时最少 因为要保证用时最少,要先把时长由小到大排序. 没排序 WA了几小时..链接 #include <iostream> #include< ...

  3. 2019最新Android面试题

    原文链接:https://blog.csdn.net/wen_haha/article/details/88362469版权声明:本文为博主原创文章,转载请附上博文链接! 前言 金三银四到来了,找工作 ...

  4. tomcat 启动失败 和闪退 和 启动成功却没有页面显示

    1.解压版tomcat 将tomcat解压至英文目录下, 在系统环境变量里面配置 JAVA_HOME 和CATALINA_HOME (就是tomcat的安装目录) 在path中配置 %CATALINA ...

  5. java urlEncode 和urlDecode的用法

    前台进行http请求的时候 如果要对中问进行编码,要使用两次编码 String zhName=urlEncode.encode((urlEncode.encode("中文",&qu ...

  6. IntentFilter的相关问题解析

    IntentFilter是配合Intent而生的,你有目标行动或者结果,那么那些行动和结果就会有他完成的特定要求,这些要求就是IntentFilter,可以理解为Intent和IntentFilter ...

  7. .Net中的强名称(Strong Name)

    我在CSDN上的文章, 转载与此: .Net中的强名称(Strong Name) http://blog.csdn.net/Anor/article/details/3649646

  8. CREATE OPERATOR CLASS - 定义一个新的操作符类

    SYNOPSIS CREATE OPERATOR CLASS name [ DEFAULT ] FOR TYPE data_type USING index_method AS { OPERATOR ...

  9. WPF学习- AllowDrop 用户控件启用拖放功能

    知识点: 创建自定义用户控件(UserControl) 使用户控件成为拖动源 使用户控件成为放置目标 使面板能够接收从用户控件放置的数据 创建项目: 1.新建WPF项目(Wpf-AllowDrop) ...

  10. vs code 用户代码片段 html.json

    {     // Place your snippets for html here. Each snippet is defined under a snippet name and has a p ...