Pagini recente » Cod sursa (job #2627664) | Cod sursa (job #826331) | Cod sursa (job #2263293) | Cod sursa (job #450872) | Cod sursa (job #1575660)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int nmax = 50005;
vector <int> g[nmax];
bool viz[nmax];
int grint[nmax];
int main()
{
ifstream fin ("sortaret.in");
ofstream fout ("sortaret.out");
ios_base::sync_with_stdio(false);
int n, m, i, j, x, y;
bool found=false;
fin >> n >> m;
for(i=1; i<=m; i++)
{
fin >> x >> y;
grint[y]++;
g[x].push_back(y);
}
for(i=1; i<=n; i++)
{
found=false;
for(j=1; j<=n && !found; j++)
if(grint[j]==0 && !viz[j])
{
viz[j]=true;
found=true;
x=j;
}
fout << x << " ";
for(j=0; j<g[x].size(); j++)
grint[g[x][j]]--;
}
fin.close();
fout.close();
return 0;
}