Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 12676 | Accepted: 5368 |
Description
Given a description of the current set of R (F-1 <= R <= 10,000) paths that each connect exactly two different fields, determine the minimum number of new paths (each of which connects exactly two fields) that must be built so that there are at least two separate routes between any pair of fields. Routes are considered separate if they use none of the same paths, even if they visit the same intermediate field along the way.
There might already be more than one paths between the same pair of fields, and you may also build a new path that connects the same fields as some other path.
Input
Lines 2..R+1: Each line contains two space-separated integers which are the fields at the endpoints of some path.
Output
Sample Input
7 7
1 2
2 3
3 4
2 5
4 5
5 6
5 7
Sample Output
/*
* Author: sweat123
* Created Time: 2016/6/21 20:07:00
* File Name: main.cpp
*/
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<time.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1<<30
#define MOD 1000000007
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define pi acos(-1.0)
using namespace std;
const int MAXN = ;
struct node{
int to;
int next;
}edge[MAXN<<];
int pre[MAXN],vis[MAXN],pa[MAXN],dfn[MAXN],low[MAXN],n,m,ind;
int px[MAXN],py[MAXN];
int pcnt;
void add(int x,int y){
edge[ind].to = y;
edge[ind].next = pre[x];
pre[x] = ind ++;
}
int find(int x){
if(pa[x] != x)pa[x] = find(pa[x]);
return pa[x];
}
void dfs(int rt,int k,int fa){
dfn[rt] = low[rt] = k;
for(int i = pre[rt]; i != -; i = edge[i].next){
int t = edge[i].to;
if(!dfn[t] && t != fa){
dfs(t,k+,rt);
low[rt] = min(low[rt],low[t]);
if(low[t] > dfn[rt]){
px[pcnt] = rt,py[pcnt++] = t;
} else {
int fx = find(t);
int fy = find(rt);
if(pa[fx] != pa[fy]){
pa[fx] = fy;
}
}
} else if(t != fa){//bridge is differenet from point
low[rt] = min(low[rt],dfn[t]);
}
}
}
int d[MAXN],f[MAXN];
int main(){
while(~scanf("%d%d",&n,&m)){
ind = ;
pcnt = ;
memset(pre,-,sizeof(pre));
for(int i = ; i <= m; i++){
int x,y;
scanf("%d%d",&x,&y);
add(x,y),add(y,x);
}
for(int i = ; i <= n; i++){
pa[i] = i;
}
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
dfs(,,-);
//for(int i = 1; i <= n; i++){
//cout<<dfn[i]<<' '<<low[i]<<endl;
//}
//cout<<endl;
memset(d,,sizeof(d));
memset(f,-,sizeof(f));
int pnum = ;
for(int i = ; i <= n; i++){
int fx = find(i);
if(f[fx] == -)f[fx] = ++pnum;
f[i] = f[fx];
}
for(int i = ; i < pcnt; i++){
d[f[px[i]]] ++,d[f[py[i]]] ++;
}
int ans = ;
for(int i = ; i <= pnum; i++){
if(d[i] == )ans ++;
}
printf("%d\n",(ans + ) / );
}
return ;
}