Pagini recente » Istoria paginii runda/don.t_chew/clasament | Diferente pentru utilizator/florinhaja intre reviziile 77 si 78 | Istoria paginii utilizator/alexc23 | Diferente pentru utilizator/vladdobro07 intre reviziile 45 si 21 | Cod sursa (job #1355276)
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fs first
#define sc second
#define pob pop_back
#define pub push_back
#define puf push_front
#define pof pop_front
#define eps 1E-7
#define sz(a) a.size()
#define count_one __builtin_popcount;
#define count_onell __builtin_popcountll;
#define fastIO ios_base::sync_with_stdio(false)
#define PI (acos(-1.0))
#define linf (1LL<<62)//>4e18
#define inf (0x7f7f7f7f)//>2e9
#define MAXN 50001
#define DEBUG 1
#ifdef DEBUG
#define D(x) x
#else
#define D(x)
#endif
ifstream f("sortaret.in");
ofstream g("sortaret.out");
int n, m;
int x, y;
int deg[MAXN] = {0};
deque<int> S;
vector<int> vec[MAXN], sol;
int main()
{
f >> n >> m;
for (int k = 0; k < m; ++k) {
f >> x >> y;
vec[x].pub(y);
deg[y]++;
}
for(int i = 1; i <= n; ++i)
if(deg[i] == 0)
S.pub(i);
while (!S.empty()) {
int nod = S.front(); S.pof();
sol.pub(nod);
for (vector<int>::iterator it = vec[nod].begin(); it != vec[nod].end(); it++) {
deg[*it]--;
if(deg[*it] == 0)
S.pub(*it);
}
}
if(sz(sol) < n)
g << "-1";
else
for(auto it = sol.begin(); it != sol.end(); it++) {
g << *it << " ";
}
return 0;
}