题解

1 条题解

  • 0
    @ 2018-11-06 17:00:52

    做法很简单,2~n枚举点,每次建并查集搞搞,除了枚举的点以外都连,然后查一下1和n在不在一个集合,不在就说明枚举的点是一定经过的点

    #include <bits/stdc++.h>
    using namespace std;
    const int N = 1e4 + 10;
    inline int read()
    {
        register int num = 0;
        register char ch;
        register bool flag = false;
        while ((ch = getchar()) == ' ' || ch == '\n' || ch == '\r');
        if (ch == '-')flag = true; else num = ch ^ 48;
        while ((ch = getchar()) != ' '&&ch != '\n'&&ch != '\r'&&~ch)
            num = (num << 1) + (num << 3) + (ch ^ 48);
        if (flag)return -num; return num;
    }
    int fa[N],ans[N];
    struct Node {
        int x, y;
    }edge[N];
    inline int findf(register int x)
    {
        if (fa[x] == x)return x;
        return fa[x] = findf(fa[x]);
    }
    
    int main()
    {
        register int n = read(), m = read();
        for (register int i = 1; i <= m; ++i)edge[i].x = read(), edge[i].y = read();
        for (register int i = 2; i != n; ++i)
        {
            for (register int j = 1; j <= n; ++j)fa[j] = j;
            for (register int j = 1; j <= m; ++j)
            {
                register int fx = findf(edge[j].x), fy = findf(edge[j].y);
                if (edge[j].x != i && edge[j].y != i && fx != fy)fa[fx] = fy;
            }
            if (findf(1) != findf(n))ans[++ans[0]] = i;
        }
        printf("%d\n", ans[0]);
        for (register int i = 1; i <= ans[0]; ++i)printf("%d ", ans[i]);
        return 0;
    }
    
  • 1

信息

难度
10
分类
(无)
标签
(无)
递交数
9
已通过
0
通过率
0%
上传者