Cod sursa(job #2089935)

Utilizator Radu2kRadu Salavat Radu2k Data 17 decembrie 2017 13:01:00
Problema Sortare topologica Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
vector <int> v(100);
ifstream fin("date.in");

int n,m;
struct v{
int x;
int y;
}w[100];


void read()
{fin>>n;
  fin>> m;
 for(int i=0;i<m;i++)
    fin>>w[i].x>>w[i].y;
}

void prelucreaza(int x)
{int ok=1;

       for(int i=0;i<m;i++)
        {
            if(w[i].y==x and v[w[i].x]==0)
                {prelucreaza(w[i].x);
                ok=0;}
            else
                if(w[i].y==x and v[w[i].x]==1)
                {
                    cout<<x<<' ';
                    v[x]=1;
                    break;
                ok=0;}

        if(i==m-1 and ok==1)
        {
            cout<<x<<' ';
            v[x]=1;
        }
        }

}

int main()
{
    read();
for(int i=3;i<=n;i++)
    prelucreaza(i);



    return 0;
}