Codeforces 659E New Reformdfs __ACM

Source: Internet
Author: User
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; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.