标签:
1 /*
2 图论/暴力:这是个连通的问题,每一次把所有度数为1的砍掉,把连接的点再砍掉,总之很神奇,不懂:)
3 */
4 #include <cstdio>
5 #include <cstring>
6 #include <algorithm>
7 #include <cmath>
8 using namespace std;
9
10 const int MAXN = 1e2 + 10;
11 const int INF = 0x3f3f3f3f;
12 int cnt[MAXN];
13 int a[MAXN];
14 bool g[MAXN][MAXN];
15
16 int main(void) //Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces
17 {
18 // freopen ("B.in", "r", stdin);
19 int n, m;
20 while (scanf ("%d%d", &n, &m) == 2)
21 {
22 memset (cnt, 0, sizeof (cnt));
23 memset (g, false, sizeof (g));
24 for (int i=1; i<=m; ++i)
25 {
26 int x, y; scanf ("%d%d", &x, &y);
27 cnt[x]++; cnt[y]++;
28 g[x][y] = g[y][x] = true;
29 }
30
31 int t = 0; int ans = -1;
32 do{
33 t = 0;
34 for (int i=1; i<=n; ++i)
35 {
36 if (cnt[i] == 1) {cnt[i]--; a[++t] = i;}
37 }
38 for (int i=1; i<=t; ++i)
39 {
40 for (int j=1; j<=n; ++j)
41 {
42 if (g[a[i]][j] == true) cnt[j]--;
43 }
44 }
45 ++ans;
46 }while (t > 0);
47
48 printf ("%d\n", ans);
49 }
50
51 return 0;
52 }
53
54
55 /*
56 3 3
57 1 2
58 2 3
59 3 1
60 6 3
61 1 2
62 2 3
63 3 4
64 6 5
65 1 4
66 2 4
67 3 4
68 5 4
69 6 4
70 */
图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces
标签:
原文地址:http://www.cnblogs.com/Running-Time/p/4550003.html