Topic Link:
Http://codeforces.com/problemset/problem/659/E :
Given n-point and M-bar bidirectional edges, change the bidirectional edge to a one-way edge, asking the minimum number of vertices that cannot be reached. Analysis:
The entry is 0 if it is not reachable.
DFS determines whether a ring exists in each connected block, and if there is a ring, it can guarantee that the entry of each point in the ring is greater than or equal to 1. Otherwise, the manage, the head of the degree of 0. Code:
#include <cstdio> #include <queue> #include <cstring> #include <
Iostream> #include <vector> using namespace std;
const int MAXN = 1e5 + 5;
vector<int>v[maxn];
int VIS[MAXN];
int ans;
void Dfs (int now, int pre) {if (Vis[now]) {ans = 0;return;}
Vis[now] = 1;
for (int i = 0; i < v[now].size (); i++) {if (V[now][i]!= pre) DFS (V[now][i], now);
{int main (void) {int n, m;scanf ("%d%d", &n,&m);
int A, B;
for (int i = 0; i < m i++) {scanf ("%d%d", &a, &b);
V[a].push_back (b);
V[b].push_back (a);
memset (Vis, 0, sizeof (VIS));
int res = 0;
for (int i = 1; I <= n; i++) {if (vis[i]) continue;
ans = 1;
DFS (i, 0);
res + ans;
printf ("%d\n", res);
return 0; }