Cod sursa(job #2676882)

Utilizator roninresResceau Filip roninres Data 25 noiembrie 2020 10:22:45
Problema Sortare topologica Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.48 kb
// topsort.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
using namespace std;
int viz[222], a[11][11],postordine[22],nr=0,n;
void Citire()
{
    int m, x, y; 
        cin >> n >> m;
        while (m--)
        {
            cin >> x >> y;
            a[x][0]++; a[x][a[x][0]] = y;
            a[y][0]++; a[y][a[y][0]] = x;
        }
}
void DFS(int x)
{
    int i;
    viz[x] = 1;
    for (i = 1; i <= a[x][0]; i++)
        if (!viz[a[x][i]])
            DFS(a[x][i]);
    postordine[++nr] = x;
}
int main()
{
    int i;
    Citire();
    for (i = 1; i <= n; i++)
        if (!viz[i])
            DFS(i);
    cout << "ordinea topologica a varfurilor";
    for (i = n; i > 0; i--)
        cout << postordine[i] << " " << endl;
    std::cout << "Hello World!\n";
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file