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. HDFS执行getDatanodeReport时权限不足的解决办法

    通过JAVA获取HDFS的getDatanodeReport方法时,报权限不足的错误信息. org.apache.hadoop.ipc.RemoteException(org.apache.hadoo ...

  2. C#不允许在foreach循环中改变数组或集合中元素的值(注:成员的值不受影响)

    C#不允许在foreach循环中改变数组或集合中元素的值(注:成员的值不受影响),如以下代码将无法通过编译. foreach (int x in myArray) { x++; //错误代码,因为改变 ...

  3. python vs java的rsa加密

    首先:java的加密解密模块需要更加精细的算法细节指定 java的加密方式 javax.crypto.Cipher,定义的获取方式 tatic Cipher getInstance(String tr ...

  4. mysql 忘记密码 登陆+修改密码

    step1: 苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server) step2: 进入终端输入:cd /usr/local ...

  5. Vue.js学习笔记--3.表单输入绑定

    整理自官网教程 -- https://cn.vuejs.org/ 利用v-model可以实现表单元素的value与后台数据的双向绑定,具体用法如下: <!--文本--> <input ...

  6. javascript之input获取的时间减1秒&&t时间恢复

    将输入得到的时间减少1秒:20:00:00  ———  19:59:59    方法一:普通时间转换 endDateMap(date){ var h = new Date(date).getHours ...

  7. ES6学习笔记(2)----变量的解构和赋值

    参考书<ECMAScript 6入门>http://es6.ruanyifeng.com/ 变量的解构和赋值 本质上:只要模式匹配,左边的变量就能被赋予右边对应的值 原则: 解构赋值的规则 ...

  8. eclipse设置Tomcat超级详细

    刚接触Ajax,创建了jsp文件发现错误 必备软件:tomcat(从apache的官方网站上下载一个,我的是apache-tomcat-8.0.28) 需要下载tomcatPluginV321.zip ...

  9. VUE 入坑系列 一 事件

    html代码 <div id="app"> <button v-on:click="counter += 1">加1</butto ...

  10. Farseer.net轻量级ORM开源框架 V1.2.1版本升级消息

    提交版本V1.2.11.修复实体未设置主键时,无法找到主键ID字段,改为无主键时默认为"ID”字段2.新增:SqlServer2000Provider数据库驱动3.新增:DbContextI ...