Pagini recente » Cod sursa (job #641516) | Cod sursa (job #2559149) | Cod sursa (job #660062) | Cod sursa (job #23380) | Cod sursa (job #3146211)
#include <bits/stdc++.h>
using namespace std;
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
};
InParser in("sortaret.in");
ofstream out("sortaret.out");
vector <int> v[50001];
int lista[50001], cnt;
bool viz[50001];
void dfs(int nod)
{
viz[nod] = 1;
for(auto it:v[nod])
if(!viz[it])
dfs(it);
lista[++cnt] = nod;
}
int main()
{
int n, m, x, y;
in >> n >> m;
for(int i = 1; i <= m; i++)
{
in >> x >> y;
v[x].push_back(y);
}
for(int i = 1; i <= n; i++)
if(!viz[i])
dfs(i);
for(int i = n; i >= 1; i--)
out << lista[i] << " ";
return 0;
}