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\n",ans);
}
posted @ 2019-08-05 21:56  Y15BeTa  阅读(84)  评论(0编辑  收藏  举报