不知道哪里错了
代码
#include<bits/stdc++.h>
#define uf(x,y,z) for(int x=y;x<=z;x++)
#define df(x,y,z) for(int x=y;x>=z;x--)
#define int long long
#define r read()
#define w(x) write(x)
using namespace std;
int dis[100010],st,n,m,x,y;
struct node
{
int l;
map<int,int>s;
}a[100010];
int read()
{
int x=0,t=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')t=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*t;
}
void write(int x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9)write(x/10);
putchar(x%10+'0');
}
void bfs()
{
queue<int> q;
q.push(st);
while(!q.empty())
{
int u=q.front();
q.pop();
uf(i,1,a[u].l)
{
int v=a[u].s[i];
if(dis[v]<dis[u]+1)
{
dis[v]=dis[u]+1;
q.push(v);
}
}
}
}
signed main()
{
n=r;m=r;
uf(i,1,n)dis[i]=1;
uf(i,1,m)
{
x=r;y=r;
a[x].s[++a[x].l]=y;
dis[y]=0;
}
uf(i,1,n)
{
if(dis[i]==1)st=i;
}
bfs();
uf(i,1,n)
{
w(dis[i]);
putchar('\n');
}
return 0;
}