BestCoder Round #73 (div.2)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BestCoder Round #73 (div.2)相关的知识,希望对你有一定的参考价值。

 

1001 Rikka with Chess

ans = n / 2 + m / 2

1002 Rikka with Graph

题意:n + 1条边,问减去至少一条使剩下的图连通的方案数。

分析:原来暴力选一条或两条就行了,脑子笨了。判连通用BFS或并查集,此题并查集更好

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <set>
using namespace std;

typedef long long ll;
const int N = 1e2 + 5;
struct DSU  {
    int rt[N];
    DSU()   {
        memset (rt, -1, sizeof (rt));
    }
    int Find(int x) {
        return rt[x] == -1 ? x : rt[x] = Find (rt[x]);
    }
    void Union(int x, int y)    {
        x = Find (x);   y = Find (y);
        if (x == y) return ;
        rt[x] = y;
    }
    bool same(int x, int y) {
        return Find (x) == Find (y);
    }
};
int u[N], v[N];

int main(void)  {
    int T;  scanf ("%d", &T);
    while (T--) {
        int n;  scanf ("%d", &n);
        for (int i=0; i<n+1; ++i)    {
            scanf ("%d%d", u+i, v+i);
        }
        int ans = 0;
        for (int i=0; i<n+1; ++i)   {
            DSU dsu;    int edge = 0;
            for (int j=0; j<n+1; ++j)   {
                if (i == j) continue;
                if (!dsu.same (u[j], v[j]))  {
                    dsu.Union (u[j], v[j]);
                    edge++;
                }
                if (edge == n - 1)  break;
            }
            if (edge == n - 1)  ans++;
        }
        for (int i=0; i<n+1; ++i)   {
            for (int j=i+1; j<n+1; ++j)   {
                DSU dsu;    int edge = 0;
                for (int k=0; k<n+1; ++k)   {
                    if (k == i || k == j)   continue;
                    if (!dsu.same (u[k], v[k]))  {
                        dsu.Union (u[k], v[k]);
                        edge++;
                    }
                    if (edge == n - 1)  break;
                }
                if (edge == n - 1)  ans++;
            }
        }
        printf ("%d\n", ans);
    }

    return 0;
}

1003 Rikka with Array

待补

 

以上是关于BestCoder Round #73 (div.2)的主要内容,如果未能解决你的问题,请参考以下文章

BestCoder Round #78 (div.2)

BestCoder Round #69 (div.2)(hdu5611)

BestCoder Round #66 (div.2) hdu5592

BestCoder Round #71 (div.2)

BestCoder Round #11 (Div. 2)

BestCoder Round #71 (div.2) (hdu 5620 菲波那切数列变形)