Pagini recente » Cod sursa (job #1182891) | Cod sursa (job #1249543) | Cod sursa (job #1170530) | Cod sursa (job #1277221) | Cod sursa (job #553886)
Cod sursa(job #553886)
#include <fstream.h>
ifstream f("dfs.in");
ofstream g("dfs.out");
int G[100][100],n,m,viz[100],cc=0;
void bfs(int x)
{
for(int i=1;i<=n;i++)
if(G[x][i]==1)
viz[i]=1;
}
int main()
{
int i,x,y,sf,incep,u;
f>>n>>m;
for(i=1;i<=m;i++)
f>>x>>y,G[x][y]=G[y][x]=1;
for(i=1;i<=n;i++)
if(viz[i]==0)cc++,bfs(i);
g<<cc<<'\n';
f.close();
g.close();
return 0;
}