16 pts 求助大佬,赏关

B3644 【模板】拓扑排序 / 家谱树

拓扑排序写挂了
by Netherite_Sword @ 2023-04-15 11:44:37


首先呢是输出反了 ```cpp for(int i=n;i>=1;i--){cout<<a[i]<<"";} ``` 改了就能58pts [记录详情](https://www.luogu.com.cn/record/108111505) 然后呢,问题就出在数组f,相当于是边的方向反了 ```cpp #include <bits/stdc++.h> using namespace std; int n,d[109],a[109]; bool f[109][109]; queue<int>q; int tip; int main(){ cin>>n; for (int i=1;i<=n;i++){ bool flag=false; while(1){ int x; cin>>x; if(x==0){ if(!flag){ q.push(i); } break; } else{ f[x][i]=true; d[i]++; flag=true; } } } while(!q.empty()){ int s=q.front(); q.pop(); tip++; a[tip]=s; for(int i=1;i<=n;i++){ if(f[s][i]){ d[i]--; if(d[i]==0){ q.push(i); } } continue; } } for(int i=n;i>=1;i--) { cout<<a[i]<<' '; } return 0; } ``` 稍作修改就过了[记录详情](https://www.luogu.com.cn/record/108112151)
by __ZTY__ @ 2023-04-15 13:08:01


|