求出最长路.....
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = 1e6+;
int head[maxn], dis[], num, val[];
struct node
{
int to, nextt, c;
}e[maxn];
void add(int u, int v, int c) {
e[num].to = v;
e[num].nextt = head[u];
e[num].c = c;
head[u] = num++;
}
void init() {
mem1(dis);
mem1(head);
num = ;
}
int dfs(int u) {
if(~dis[u])
return dis[u];
int ret = val[u], ans = ;
for(int i = head[u]; ~i; i = e[i].nextt) {
int v = e[i].to;
ans = max(ans, dfs(v));
}
return dis[u] = ans+ret;
}
int main()
{
int n, x, y;
while(cin>>n) {
init();
for(int i = ; i<=n; i++) {
scanf("%d", &val[i]);
scanf("%d", &x);
while(x--) {
scanf("%d", &y);
add(y, i, val[i]);
}
}
for(int i = ; i<=n; i++) {
if(dis[i]==-) {
dis[i] = dfs(i);
}
}
int ans = ;
for(int i = ; i<=n; i++) {
ans = max(ans, dis[i]);
}
printf("%d\n", ans);
}
return ;
}