@[lianshixiong](/user/719140) 完了你的写法不是正解
by No_I_Can @ 2023-08-16 11:05:43
建议重构代码或学习新算法:拓扑排序
by No_I_Can @ 2023-08-16 11:06:20
@[lianshixiong](/user/719140) 你甚至样例都过不了怎么会AC
by No_I_Can @ 2023-08-16 11:06:53
@[lianshixiong](/user/719140)
>有些杂务没有需要准备的工作只描述一个单独的 0。
by ryf20100124 @ 2023-08-16 11:08:23
```cpp
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN=1e5+5;
int n,len=0,ans=0;
int t[MAXN],a[MAXN];
signed main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>i>>t[i];
int k;
ans=0;
while(cin>>k && k!=0) ans=max(ans,a[k]);
a[i]=ans+t[i];
len=max(len,a[i]);
}
cout<<len;
return 0;
}
```
by Kobe_BeanBryant @ 2023-08-16 11:24:13
大改了一下![](//图.tk/e)
by Kobe_BeanBryant @ 2023-08-16 11:24:39
求关![](//图.tk/e)
by Kobe_BeanBryant @ 2023-08-16 11:25:10
```cpp
#include<bits/stdc++.h>
using namespace std ;
const int N=1e4+10 ;
int n ;
int t[N] ;
int ind[N] , outd[N] ,anst[N];
vector<int>v[N] ;
const int mod=80112002 ;
int main(){
cin >> n ;
for(int i=1;i<=n;i++){
int x ,id,len;
cin >> id >> len ;
t[id]=len ;
while(cin >> x){
if(x==0) break ;
v[x].push_back(i) ;
ind[id]++ ;
outd[x]++ ;
}
}
queue<int> q ;
for(int i=1;i<=n;i++){
if(!ind[i]){
q.push(i) ;
anst[i]=t[i] ;
}
}
while(!q.empty()){
int o=q.front() ;
q.pop() ;
for(int i=0;i<v[o].size();i++){
int p=v[o][i] ;
ind[p]-- ;
anst[p]=max(anst[p],anst[o]+t[p]) ;
if(!ind[p]) q.push(p) ;
}
}
int maxn=-1 ;
for(int i=1;i<=n;i++){
if(!outd[i]){
maxn=max(maxn,anst[i]) ;
}
}
cout << maxn ;
return 0 ;
}
by z_ty1002 @ 2023-08-16 19:57:42