题目链接
https://www.luogu.org/problem/P1407
分析
根据二分图匹配的性质,可以发现,若一对夫妻在一个强连通分量中,
通过调整,便可再形成新的局面,是不稳定的婚姻;
用Tarjan算法求出强连通分量,判断即可。
AC代码
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
using namespace std;
const int maxn = 4e3 + 5, maxm = 2e4 + 5;
int head[2 * maxn], eid;
struct Edge {
int v, next;
} edge[maxn + maxm];
inline void insert(int u, int v) {
edge[++eid].v = v;
edge[eid].next = head[u]