传送门
题目描述
分析
比较有趣的一个构造题
首先最后答案是一定存在的,没有答案不存在的情况
一条边连接两个点,如果不存在独立边集的话,说明只有不到
2
∗
n
2 * n
2∗n个点收到了影响,也就是说剩下的点超过了
n
n
n,可以构成独立点集
代码
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define dl(x) printf("%lld\n",x);
#define di(x) printf("%d\n",x);
#define _CRT_SECURE_NO_WARNINGS
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int INF = 0x3f3f3f3f;
const int N = 2e6 + 10;
const ll mod = 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
template<typename T>inline void read(T &a) {
char c = getchar(); T x = 0, f = 1; while (!isdigit(c)) {if (c == '-')f = -1; c = getchar();}
while (isdigit(c)) {x = (x << 1) + (x << 3) + c - '0'; c = getchar();} a = f * x;
}
int gcd(int a, int b) {return (b > 0) ? gcd(b, a % b) : a;}
bool st[N];
int n,m;
VI ans;
void init(){
for(int i = 1;i <= n * 3;i++) st[i] = false;
ans.clear();
}
bool solve(){
read(n),read(m);
init();
for(int i = 1;i <= m;i++){
int x,y;
read(x),read(y);
if(!st[x] && !st[y]){
ans.pb(i);
st[x] = true,st[y] = true;
}
}
if(ans.size() >= n) return true;
ans.clear();
for(int i = 1;i <= 3 * n;i++){
if(!st[i]) ans.pb(i);
}
return false;
}
int main() {
int T;
read(T);
while(T--){
if(solve()) puts("Matching");
else puts("IndSet");
for(int i = 0;i < n;i++) printf("%d ",ans[i]);
puts("");
}
return 0;
}
/**
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the animal protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/