Cod sursa(job #1666712)

Utilizator theodor1289Theodor Amariucai theodor1289 Data 28 martie 2016 12:16:07
Problema Parcurgere DFS - componente conexe Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <fstream>
using namespace std;
ifstream fin("dfs.in");
ofstream fout("dfs.out");
int n, m, ctr, x, y;
bool viz[100010];

struct lista {
int val;
lista* urm;
};
lista* g[100010];

void DFS(int nodcurent)
{
    lista *p, *nod;
    viz[nodcurent]=1;

    while(p->urm)
    {
        DFS(p->val);
        p=p->urm;
    }


}

void add(nod &sursa, int dest)
{
    lista *p=new lista;
    p->val=dest;
    p->urm=sursa;
    sursa=p;
}

int main()
{
    fin>>n>>m;

    for(int i=1;i<=m;i++)
    {
        fin>>x>>y;
        add(g[x], y);
        add(g[y], x);
    }

    for(int i=1;i<=n;i++)
        if(!viz[i])
    {
        ctr++;
        DFS(i);
    }

    return 0;
}