LuoguP1113 杂务

其实不用写topo

像我这样不会topo的蒟蒻

借鉴了洛谷第一篇题解

#include<cstdio>
#include<algorithm>
using namespace std;

int n,dep[100005],ans;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int now,len,fa,last=0;
		scanf("%d%d%d",&now,&len,&fa);
		while(fa){
			last=max(last,dep[fa]);
			scanf("%d",&fa);
		}
		dep[now]=last+len;
		ans=max(ans,dep[now]);
	}
	printf("%d
",ans);
}
原文地址:https://www.cnblogs.com/Y15BeTa/p/11305817.html