chen_kun @ 2024-04-03 16:10:15
一直RE,求大佬帮忙
#include<bits/stdc++.h>
using namespace std;
int n,vis[114514];
vector<unsigned long long int>g[114514];
bool toposort(){
queue<int>q;
for(int i=1;i<=n;i++) if(vis[i]==0) q.push(i);
while(q.size()){
int x=q.front();
q.pop();
cout<<x<<" ";
for(int i=0;i<g[x].size();i++){
vis[g[x][i]]--;
if(vis[g[x][i]]==0) q.push(g[x][i]);
}
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
while(1){
int t;
cin>>t;
if(t==0) break;
g[i].push_back(t);
vis[t]++;
}
}
toposort();
return 0;
}
by tjx114514 @ 2024-04-03 16:19:41
@chen_kun 把toposort的类型改成void
by chen_kun @ 2024-04-03 16:22:52
@tjx114514 已过,感谢大佬(关注您了)
by Lawrence003 @ 2024-04-03 16:49:21
return true;