请使用链式前向星或 `vector`
by bykem @ 2022-11-24 20:47:07
$MLE$ 了,收到
by retep @ 2022-11-24 20:49:09
@[wsfxk](/user/376161) 大佬求教QWQ
by CooooldWind_ @ 2022-11-24 20:50:22
125MB最多让你开 $3e7$ 个int 吧好像(
换个好点的存图方式吧(或者把nxt改成一个vector(虽然空的vector空间也不小,不过最后肯定比你这个3e7好点)
by Ranger_HoFr @ 2022-11-24 20:50:37
```cpp
#include<bits/stdc++.h>
using namespace std;
int n,m,sted_sum,sorted[100001];
short in_deg[100001],ans[100001];
struct node{vector<int> nxt;}excel[100001];
int main(){
scanf("%d %d",&n,&m);
for(int i = 0;i < m;i++){
int x,y;
scanf("%d %d",&x,&y);
excel[x].nxt.push_back(y);
in_deg[y]++;
}
queue<int> q;
for(int i = 1;i <= n;i++){
if(in_deg[i] == 0) q.push(i);
ans[i] = 1;
}
while(!q.empty()){
int temp = q.front();
q.pop();
sorted[sted_sum++] = temp;
for(int i = 0;i < excel[temp].nxt.size();i++){
int to = excel[temp].nxt[i];
if(in_deg[to] > 0){
in_deg[to]--;
if(in_deg[to] == 0){
q.push(to);
ans[to] = ans[temp] + 1;
}
}
}
}
for(int i = 1;i <= n;i++) printf("%d\n",ans[i]);
return 0;
}
```
然后我WA了#4…
by CooooldWind_ @ 2022-11-24 21:01:39
@[ColdWind6666](/user/747369) 好吧自查出了是short的问题。
~~short真的害死人~~
by CooooldWind_ @ 2022-11-24 21:03:43