Simple application of Eoj 1816 and check-up--judgment map Unicom

Source: Internet
Author: User

Title: eoj1816

Topic Analysis: Determine whether the graph is connected, the DFS traversal graph algorithm can be used. Here I'm using a method to check the set. Each node is treated as a collection when initialized, and two collections are merged each given an edge. Finally, all points are traversed, and several sets have several connected components, if only one of the set description diagrams is connected.

AC Code:

#include <iostream>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <string>

#include <vector>

#include <map>

#include <algorithm>

using namespace Std;

int set[1000005];

int find (int x) {

returnx==set[x]?x: (Set[x]=find (set[x]));

}

int main ()

{

int n,m,i,x,y;

scanf ("%d%d", &n,&m);

for (i=1;i<1000005;++i)

set[i]=i;

for (i=0;i<m;++i) {

int A, b;

scanf ("%d%d", &a,&b);

int Fx=find (a), fy=find (b);

set[fx]=fy;

   }

int cnt=0;

for (i=1;i<=n;++i)

if (set[i]==i)

++cnt;

if (cnt==1)

printf ("yes\n");

Else printf ("no\n");

return 0;

}

Simple application of Eoj 1816 and check-up--judgment map Unicom

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.