题意, 给你一个无向图,给几个点染色。求这样的点的点集:删去这个点后,图剩余的联通块中,有至少一个不含有染色点。
题解:首先知道,符合要求的点一定是割点,我们在原图上跑点双联通分量,然后进行缩点,缩点方式:每个双连通分量缩为一个点、然后新建虚拟节点作为割点,然后链接成为树。 形成树后,在树上统计信息。如果一个虚拟节点(割点)的某孩子中或者父节点方向没有染色点。则该割点为所求点。
下面是ac代码:
// % everyone
#include<cstdio>
#include<iostream>
#include<cstring>
#include <map>
#include <queue>
#include <set>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <bitset>
#include <array>
#include <cctype>
#include <time.h>
#pragma GCC optimize(2)
void read_f() { freopen("1.in", "r", stdin); freopen("1.out", "w", stdout); }
void fast_cin() { std::ios::sync_with_stdio(false); std::cin.tie(); }
void run_time() { std::cout << "ESC in : " << clock() * 1000.0 / CLOCKS_PER_SEC << "ms" << std::endl; }
template <typename T>
bool bacmp(const T & a, const T & b) { return a > b; }
template <typename T>
bool pecmp(const T & a, const T & b) { return a < b; }
#define ll long long
#define ull unsigned ll
#define _min(x, y) ((x)>(y)?(y):(x))
#define _max(x, y) ((x)>(y)?(x):(y))
#define max3(x, y, z) ( max( (x), max( (y), (z) ) ) )
#define min3(x, y, z) ( min( (x), min( (y), (z) ) ) )
#define pr(x, y) (make_pair((x), (y)))
//#define pb(x) push_back(x)
using namespace std;
const int N = 1e6+5;
int dfn[N], low[N], cnt;
int root = 1, blo;
int cut[N];
int belong[N];
int new_id[N];
int brid[N];
int ver[N<<1], ne[N<<1], he[N], tot = 1;
void add(int x, int y)
{
ver[++tot] = y;
ne[tot] = he[x];
he[x] = tot;
}
int st[N], top;
vector<int> dcc[N];
vector<int> gg[N];
void tarjan(int x)
{
dfn[x]=low[x]= ++cnt;
st[++top]=x;
if(x==root && he[x]==0)//孤立点
{
dcc[++blo].push_back(x);
gg[x].push_back(blo);
return ;
}
int flag=0;
for(int i=he[x];i;i=ne[i])
{
int y=ver[i];
if(!dfn[y])
{
tarjan(y);
low[x]=min(low[x],low[y]);
if(low[y]>=dfn[x])
{
flag++;
if(x!=root||flag>1) cut[x]=true;
blo++;
int z;
do
{
z=st[top--];
dcc[blo].push_back(z);
gg[z].push_back(blo);
}while(z!=y);
dcc[blo].push_back(x);
gg[x].push_back(blo);
}
}
else low[x]=min(low[x],dfn[y]);
}
}
int the[N], tver[N], tne[N], ttot;
void tadd(int x, int y)
{
tver[++ttot] = y;
tne[ttot] = the[x];
the[x] = ttot;
}
bool gflag[N];
int _index[N];
int dp[N];
int sum;
vector<int> ans;
set<int> res;
void dfs2(int x, int fa)
{
bool ff = 1;
for (int i = the[x]; i; i = tne[i])
{
int y = tver[i]; if (y == fa) continue;
dfs2(y, x);
ff = ff && dp[y];
dp[x] += dp[y];
}
if (gflag[x] == 1) return;
if ( x > blo && (ff == 0 || (dp[x] == sum && x != 1) ) ) ans.push_back(x);
}
int num;
int n, m, p;
int d[N];
vector<int> vc;
int main()
{
scanf("%d%d%d", &n, &m, &p);
for (int i = 1; i <= m; i++)
{
int x, y; scanf("%d%d", &x, &y);
add(x, y); add(y, x);
d[x]++; d[y]++;
}
for (int i = 1; i <= n; i++) if (!dfn[i])
{root = i; tarjan(i);}
num=blo;
for(int i=1;i<=n;i++)
if(cut[i]) new_id[i]=++num, _index[num] = i;
for(int i=1;i<=blo;i++)
{
for(int j=0;j<dcc[i].size();j++)
{
int x=dcc[i][j];
if(cut[x])
{
tadd(i,new_id[x]);
tadd(new_id[x],i);
}
}
}
for (int i = 1; i <= p; i++)
{
int te; scanf("%d", &te);
for (int x : gg[te])
dp[x]++, sum++, gflag[x] = 1;
if (cut[te]) dp[new_id[te]]++, sum++, gflag[new_id[te]] = 1;
}
dfs2(1, 0);
for (int x : ans)
{
vc.push_back(_index[x]);
}
printf("%d\n", vc.size());
bool flag = 1;
sort(vc.begin(), vc.end());
for (int i = 0; i < vc.size(); i++)
{
if (flag) flag = 0;
else printf(" ");
printf("%d", vc[i]);
}
puts("");
return 0;
}