题解 CF1198C 【Matching vs Independent Set】

· · 题解

另外两篇题解有些误人子弟了,根本就没有 Impossible 的情况,这道题实际上是一道构造题

我们每加入一条边,如果这条边的两个端点都没有被标记,那么我们把这两个端点标记一下,并将这条边加入边独立集中

加入所有边后,所有未标记的点即为点独立集中的点

正确性显然

为什么没有 Impossible?设最后边独立集中有 x 条边,则点独立集中有 3n-x 个点,易知这二者中必有一个 \ge n

const int N = 500010;
bool book[N];
int n,m,ans[N],cnt;
int main()
{
    int T = read();
    while(T--)
    {
        n = read(),m = read();cnt = 0;
        for(int i = 1;i <= 3 * n;i++) book[i] = 0;
        for(int i = 1;i <= m;i++)
        {
            int u = read(),v = read();
            if(!book[u] && !book[v]) book[u] = book[v] = 1,ans[++cnt] = i;
        }
        if(cnt <= n)
        {
            puts("IndSet");int now = 0;
            for(int i = 1;i <= 3 * n && now < n;i++)
                if(!book[i]) pprint(i),now++;
            putchar('\n');
        }
        else
        {
            puts("Matching");
            for(int i = 1;i <= n;i++) pprint(ans[i]);
            putchar('\n');
        }
    }
}