Pagini recente » Cod sursa (job #2846057) | Cod sursa (job #1189114) | Cod sursa (job #2456019) | Cod sursa (job #1502866) | Cod sursa (job #1213145)
#include <fstream>
#include <iostream>
#include <vector>
#include <bitset>
#include <string.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <deque>
using namespace std;
const char infile[] = "sortaret.in";
const char outfile[] = "sortaret.out";
ifstream fin(infile);
ofstream fout(outfile);
const int MAXN = 100005;
const int oo = 0x3f3f3f3f;
typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;
const inline int min(const int &a, const int &b) { if( a > b ) return b; return a; }
const inline int max(const int &a, const int &b) { if( a < b ) return b; return a; }
const inline void Get_min(int &a, const int b) { if( a > b ) a = b; }
const inline void Get_max(int &a, const int b) { if( a < b ) a = b; }
Graph g;
int n, m, in[MAXN];
priority_queue<int, vector <int>, greater<int> > heap;
int main() {
cin.sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen(infile, "r", stdin);
freopen(outfile, "w", stdout);
#endif
fin >> n >> m;
while(m -- ) {
int x, y;
fin >> x >> y;
g[x].push_back(y);
++ in[y];
}
/// Minimum lexicographic topological sort
for(int i = 1 ; i <= n ; ++ i)
if(in[i] == 0)
heap.push(i);
while(!heap.empty()) {
int node = heap.top();
heap.pop();
fout << node << ' ';
for(It it = g[node].begin(), fin = g[node].end(); it != fin ; ++ it)
if(-- in[*it] == 0)
heap.push(*it);
}
fin.close();
fout.close();
return 0;
}