样例也不能过
代码如下:
#include<bits/stdc++.h>
using namespace std;
int n,pre[10004],dtgh[10004],len[10004];
vector<int> path[10004];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
int num;
cin>>num>>len[i];
while(true){
int before;
cin>>before;
if(!before) break;
path[before].push_back(i);
pre[i]++;
}
}
queue<int>q;
for(int i=1;i<=n;i++) if(!pre[i]) q.push(i);
while(!q.empty()){
int now=q.front();
q.pop();
for(int i=0;i<path[now].size();i++){
pre[path[now][i]]--;
if(!pre[path[now][i]]) q.push(path[now][i]);
dtgh[path[now][i]]=max(dtgh[path[now][i]],dtgh[now]+len[path[now][i]]);
}
}
int ans=0;
for(int i=1;i<=n;i++){
ans=max(ans,dtgh[i]);
}
cout<<ans;
}