标签:
[2016-01-21][HDU][1878]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; long long d[1020]; int fa[1020]; int fnd( int x){ return (x == fa[x])?x:(fa[x] = fnd(fa[x])); } void uni( int x, int y){ fa[fnd(x)] = fnd(y); } void ini( int n){ for ( int i = 0;i < n;i++) fa[i] = i; } int main(){ int n; long long m; while (~ scanf ( "%d" ,&n) && n){ scanf ( "%I64d" ,&m); memset (d,0, sizeof (d)); ini(n + 10); //读取边,并把对应的端点加入并查集 int a,b; for ( long long i = 0;i < m;i++){ scanf ( "%d%d" ,&a,&b); d[a]++;d[b]++; uni(a,b); } //判断度数 int flg = 1; for ( int i = 1;flg && i <= n;i++) if (d[i] & 1) flg = 0; //判断联通分支数 set < int > s; if (flg){ for ( int i = 1;i <= n;i++){ int f = fnd(i); if (s.count(f) == 0) s.insert(f); } } printf ( "%d\n" ,flg && (s.size() == 1)); } return 0; } |
标签:
原文地址:http://www.cnblogs.com/qhy285571052/p/5149715.html