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