传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1574
【题解】
贪心把report的点的旁边所有点破坏即可。
# include <stdio.h> # include <string.h> # include <iostream> # include <algorithm> // # include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; const int M = 5e5 + 10; const int mod = 1e9+7; # define RG register # define ST static int n, m, K, p[M]; bool isr[M]; int head[M], nxt[M], to[M], tot=0; inline void add(int u, int v) { ++tot; nxt[tot] = head[u]; head[u] = tot; to[tot] = v; } inline void adde(int u, int v) { add(u, v), add(v, u); } bool vis[M]; int ans = 0; inline void dfs(int x) { vis[x] = 1; ++ans; for (int i=head[x]; i; i=nxt[i]) if(!vis[to[i]]) dfs(to[i]); } int main() { cin >> n >> m >> K; for (int i=1, u, v; i<=m; ++i) { scanf("%d%d", &u, &v); adde(u, v); } for (int i=1; i<=K; ++i) { scanf("%d", p+i); isr[p[i]] = 1; } for (int i=1, x; i<=K; ++i) { for (int j=head[p[i]]; j; j=nxt[j]) { x = to[j]; if(!isr[x]) vis[x] = 1; } } dfs(1); cout << n-ans; return 0; }