杂务
https://www.luogu.org/problemnew/show/P1113
用DP来写,下次加拓扑
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<stdlib.h> 8 #define mem(a) memset(a,0,sizeof(a)) 9 using namespace std; 10 int f[10005]; 11 int main() 12 { 13 int t,n,time,u; 14 cin>>t; 15 int ans=0; 16 for(int i=1;i<=t;i++) 17 { 18 cin>>n>>time; 19 while((cin>>u)&&u) 20 f[i]=max(f[i],f[u]); 21 //也可以写成 int s; s=max(f[u],s); f[i]=s+time; 22 f[i]+=time; 23 ans=max(f[i],ans); 24 /*时时更新,f[i]改变的不是f[u],所以是不断取更高的, 25 因为u<i且有无限个工人,故就算存在多个u,也是求在i时的f[i]max*/ 26 } 27 cout<<ans<<endl; 28 return 0; 29 }