Pagini recente » Cod sursa (job #1215166) | Cod sursa (job #1010370) | Cod sursa (job #682003) | Cod sursa (job #622705) | Cod sursa (job #1868699)
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <ctype.h>
#include <bitset>
FILE *fin = fopen("sortaret.in", "r");
FILE *fout = fopen("sortaret.out", "w");
#define BUF 1 << 17
char buf[BUF];
int pos = BUF;
inline char next() {
if(pos == BUF)
fread(buf, 1, BUF, fin), pos = 0;
return buf[pos++];
}
inline int readInt() {
int x = 0, semn = 1;
char ch = next();
while(!isdigit(ch) && ch != '-')
ch = next();
if(ch == '-')
semn = -1, ch = next();
while(isdigit(ch))
x = x * 10 + ch - '0', ch = next();
return x * semn;
}
#define Nmax 50000
#define Mmax 100000
std::vector <int> v[Nmax + 1];
std::bitset <Nmax + 1> b;
int sol[Nmax + 1], ind;
void DFS(int nod) {
if(b[nod])
return;
b[nod] = 1;
for(int i = 0;i < v[nod].size();i++) {
int y = v[nod][i];
DFS(y);
}
sol[ind++] = nod;
}
int main() {
int N, M;
fscanf(fin, "%d%d", &N, &M);
for(int i = 0;i < M;i++) {
int x, y;
fscanf(fin, "%d%d", &x, &y);
v[x].push_back(y);
}
for(int i = 1;i <= N;i++)
DFS(i);
for(int i = ind - 1;i >= 0;i--)
fprintf(fout, "%d ", sol[i]);
fclose(fin);
fclose(fout);
return 0;
}