Cod sursa(job #530846)
| Utilizator | Data | 8 februarie 2011 15:50:32 | |
|---|---|---|---|
| Problema | Parcurgere DFS - componente conexe | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include<fstream.h>
#include<stdio.h>
ifstream f("dfs.in");
ofstream g("dfs.out");
typedef struct nod{
int nr;
nod *ante;
};
nod *l[1000],*p;
long n,m,i,j,mm,max;
int v[1000];
int df(int k){
nod *q;
max++;
q=l[k];
v[k]=1;
while(q){
if(!v[q->nr])
df(q->nr);
q=q->ante;
}
return 0;
}
int main(){
f>>n>>m;
while(f>>i>>j){
p=new nod;
p->nr=j;
p->ante=l[i];
l[i]=p;
}
mm=0;
for(i=1;i<=n;i++){
max=0;
df(i);
if(max>mm)
mm=max;
}
g<<mm<<"\n";
f.close();
g.close();
return 0;
}