>Link
luogu P6378
>Description
>解题思路
一开始写的时候感觉是2-SAT的板子,结果发现处理“每个部分恰有一个关键点”的时候时间复杂度会爆,后来加了自己写的优化不知道也挂了QAQ
所以看了这个大佬的博客建图,通过增加节点的个数减少边的个数,注意数组要开大QAQ
>代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#define N 10000010
using namespace std;
stack<int> st;
struct edge
{
int to, nxt;
} e[N];
int n, m, k, cnt, h[N], col[N], dfn[N], low[N], tot, totcol, a[N], x[N], y[N], pre[N][5], sum;
bool ans;
void add (int u, int v)
{
e[++cnt] = (edge){
v, h[u]};
h[u] = cnt;
}
void tarjan (int u, int fa)
{
dfn[u