莫名奇妙就A了
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
template<typename T>void re(T&x){
x = 0; int sign = 1; char c;
do{c = getchar(); if (c == '-') sign = -1;}while(!isdigit(c));
do{x = x * 10 + c - '0'; c = getchar();}while(isdigit(c));
x *= sign;
}
const int N = 2e5 + 1000;
int n, m;
vector<ll> v[N];
queue<ll> q;
ll dist[N];
int main(){
re(n), re(m);
int x, y;
for (int i = 1; i <= m; i ++){
re(x), re(y);
v[y].push_back(x);
}
for (int i = n; i >= 1; i --){
if (!dist[i]){
q.push(i);
while (!q.empty()){
ll x = q.front(); q.pop();
if (dist[x]) continue;
if (!dist[x])
dist[x] = i;
for (int i = 0; i < v[x].size(); i ++){
q.push(v[x][i]);
}
}
while (q.size()) q.pop();
}
}
for (int i = 1; i <= n; i ++){
printf("%lld ", dist[i]);
}
return 0;
}