#include<bits/stdc++.h> usingnamespace std; #define M 10007 #define N 1007 #define INF 0x3f3f3f3f #define ll long long #define db double vector<int> g[M]; int len[M], t[M]; int n; // dp intdfs(int root){ if (t[root]) return t[root]; for (int i = 0; i < g[root].size(); i++) t[root] = max(t[root], dfs(g[root][i])); t[root] += len[root]; return t[root]; } intmain(){ ios::sync_with_stdio(false); cout.tie(NULL); cin >> n; int id, work; for (int i = 1; i <= n; i++) { cin >> id >> len[i]; while (1) { cin >> work; if (!work) { break; } g[work].push_back(id); } } int ans = 0; for (int i = 1; i <= n; i++) ans = max(ans, dfs(i)); cout << ans << endl; return0; }
intmain(){ int n=read(); for (int i=1;i<=n;i++) { int x=read(); a[i]=read(); while (int y=read()) { if (!y) break; edge[y].push_back(x); ind[x]++; } } //步骤一 for (int i=1;i<=n;i++) { if (ind[i]==0) { q.push(i); f[i]=a[i]; } }; while (!q.empty()) { int rhs=q.front(); q.pop(); //步骤二 for (int i=0;i<edge[rhs].size();i++) { int u=edge[rhs][i]; ind[u]--; if (ind[u]==0) q.push(u); //步骤三 f[u]=max(f[u],f[rhs]+a[u]); } } int ans=0; for (int i=1;i<=n;i++) { ans=max(ans,f[i]); //统计答案 } printf("%d\n",ans); return0; }