Pagini recente » Cod sursa (job #2965247) | Cod sursa (job #421098) | Cod sursa (job #3283917) | Cod sursa (job #3264469) | Cod sursa (job #3272431)
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <chrono>
#include <map>
#include <unordered_map>
#include <set>
#define f cin
#define g cout
using namespace std;
const int N = 1e5 + 5; // nr maxim de noduri
vector<int> a[N]; // Lista de ad pentru graf
//struct pct
//{
// int x, y;
//};
//
//struct comp
//{
// bool operator()(pct const X, pct const Y)
// {
// return X.y > Y.y;
// }
//};
// a.erase(std::remove(a.begin(), a.end(), 3), a.end());
//priority_queue<pct, vector<pct>, comp>q;
int parent[N];
int viz[N];
int n, m, x, y;
int in[N];
int main() {
#ifdef DONPC
ifstream f("date.in");
ofstream g("output.out");
#else
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#endif
f >> n >> m;
for (int i = 1;i <= m;i++)
{
f >> x >> y;
a[x].push_back(y);
in[y]++;
}
queue<int>q;
for (int i = 1;i <= n;i++)
if (in[i] == 0)
q.push(i);
while (!q.empty())
{
int nod = q.front();
q.pop();
g << nod << " ";
for (auto x : a[nod])
{
in[x]--;
if(in[x]==0)
q.push(x);
}
}
return 0;
}