#include #include #include using namespace std; int main(){ int n, e; cin >> n >> e; vector> adj(n); vector degree(n, 0); for(int i = 0; i < e; i++){ int a, b; cin >> a >> b; adj[a].push_back(b); degree[b]++; } priority_queue, greater> pq; for(int i = 0; i < n; i++){ if(degree[i] == 0) pq.push(i); } vector result; while(!pq.empty()){ auto m = pq.top(); pq.pop(); for(auto x : adj[m]){ degree[x]--; if(degree[x] == 0) pq.push(x); } result.push_back(m); } if(result.size() != n){ cout << "No" << endl; return 0; } for(auto x: result){ cout << x << " "; } cout << endl; return 0; }