Pagini recente » Cod sursa (job #2649730) | Cod sursa (job #1767836) | Cod sursa (job #1264203) | Cod sursa (job #1562761) | Cod sursa (job #1491855)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("dfs.in");
ofstream g("dfs.out");
struct nod
{
int inf;
nod *urm;
}*l[100005];
int n,m;
int u[100005];
void adaugnod(nod *&p,int x)
{
nod *c;
c=new nod;
c->inf=x;
c->urm=p;
p=c;
}
void citire()
{
int i;
int x,y;
f>>n>>m;
for (i=1;i<=m;i++)
{
f>>x>>y;
adaugnod(l[x],y);
adaugnod(l[y],x);
}
f.close();
}
void df(int inf,int &x)
{
nod *p;
u[inf]=1;
x++;
for (p=l[inf];p!=NULL;p=p->urm)
{
if (!u[p->inf])
df(p->inf,x);
}
}
void conex()
{
int i,maxi,x;
maxi=0;
for (i=1;i<=n;i++)
if (!u[i])
{
x=0;
df(i,x);
if (x>maxi)
maxi=x;
}
g<<maxi;
}
int main()
{
citire();
conex();
return 0;
}