比赛 |
20120711 |
评测结果 |
AAAAAAAAAAAAAAAAA |
题目名称 |
Redundant Paths |
最终得分 |
100 |
用户昵称 |
ZhouHang |
运行时间 |
0.019 s |
代码语言 |
C++ |
内存使用 |
1.03 MiB |
提交时间 |
2012-07-11 11:54:51 |
显示代码纯文本
/**
*Prob : rpathsa
*Sol : 图的桥
*Data : 2012-7-11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define maxn 10010
#define maxm 50010
struct edges {
int a, b, next;
} edge[maxm];
int f[maxn], dfn[maxn], node[maxn], tot,K,cnt[maxn];
bool mark[maxn],flag[maxn];
int min(int x,int y)
{
return x>y?y:x;
}
void insert(int a, int b) {
edge[tot].a = a, edge[tot].b = b, edge[tot].next = node[a], node[a] = tot++;
}
void dfs(int now, int cannot, int dep) {
f[now] = dfn[now] = dep;
mark[now] = true;
for (int i = node[now]; i != -1; i = edge[i].next) {
if (!mark[edge[i].b]) dfs(edge[i].b, i^1, dep + 1);
if (i != cannot) f[now] = min(f[now], f[edge[i].b]);
}
return;
}
void markdfs(int now){
flag[now] = true;
for (int i=node[now];i!=-1;i = edge[i].next)
if (!mark[i]&&!flag[edge[i].b])
markdfs(edge[i].b);
else if (mark[i]) cnt[K]++;
}
int main() {
freopen("rpathsa.in","r",stdin);
freopen("rpathsa.out","w",stdout);
int n, m, a, b, i, num;
scanf("%d%d", &n, &m);
memset(node, -1, sizeof (node));
memset(mark, false, sizeof (mark));
tot = 0;
while (m--) {
scanf("%d%d", &a, &b);
insert(a, b);
insert(b, a);
}
num = 0;
dfs(1, -1, 0);
memset(mark,false,sizeof(mark));
memset(flag,false,sizeof(flag));
memset(cnt,0,sizeof(cnt));
for (i = 0; i < tot; i++)
if (f[edge[i].a] == dfn[edge[i].b] + 1) mark[i]=mark[i^1] = true;
for (i=1,K=0;i<=n;i++)
if (!flag[i])
markdfs(i),K++;
for (i=0;i<K;i++)
if (cnt[i]==1) num++;
printf("%d\n", (num + 1) / 2);
fclose(stdin); fclose(stdout);
return 0;
}