Cod sursa(job #3274367)

Utilizator Dragos20012001Szekely Dragos Dragos20012001 Data 6 februarie 2025 16:02:38
Problema Componente tare conexe Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

ifstream fin("ctc.in");
ofstream fout("ctc.out");

vector<int> L[101];
int n, m;
bool viz[101];

void DFS(int nod)
{
    viz[nod] = 1;
    fout << nod << " ";
    for (int next : L[nod])
        if (!viz[next])
            DFS(next);
}

int main()
{
    int start;
    fin >> n >> m >> start;
    while (m--)
    {
        int x, y;
        fin >> x >> y;
        L[x].push_back(y);
        L[y].push_back(x);
    }
    for (int i = 1; i <= n; i++)
        sort(L[i].begin(), L[i].end());
    DFS(start);
    return 0;
}