Cod sursa(job #3351191)
| Utilizator | Data | 17 aprilie 2026 14:24:09 | |
|---|---|---|---|
| Problema | Sortare topologica | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.66 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n,m,d[100001];
bitset<100001> viz, a[100001];
int main()
{
fin >> n >> m;
for(int i = 1; i <= m; i++)
{
int x,y;
fin >> x >> y;
a[x][y]=1;
d[y]++;
}
int cont ;
for(int i = 1; i <= n; i++)
{
cont = 0;
for(int j = 1; j <= n && cont == 0; j++)
if(d[j] == 0 && viz[j] == 0)
{
viz[j] = 1;
cont = j;
fout << j << " ";
}
for(int j = 1; j <= n; j++)
if(a[cont][j] == 1) d[j]--;
}
}
