Cod sursa(job #2326485)
| Utilizator | Data | 23 ianuarie 2019 16:36:31 | |
|---|---|---|---|
| Problema | Parcurgere DFS - componente conexe | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int N=100001;
vector <int> a[N];
int n,m,X;
bool viz[N];
void read()
{
ifstream fin("dfs.in");
int x,y;
fin>>n>>m>>X;
for(int i =0;i<m;i++)
{
fin>>x>>y;
a[x].push_back(y);
a[y].push_back(x);
}
fin.close();
}
void dfs(int x)
{
ofstream fout("dfs.out");
fout<<x<<' ';
viz[x]=true;
for(auto y:a[x])
{
if(!viz[y])
{
dfs(y);
}
}
//step[++nr]=x;
}
int main()
{
read();
dfs(X);
return 0;
}
