1 #include "bits/stdc++.h"
 2 using namespace std;
 3 typedef long long LL;
 4 const int MAX1=2e5+5;
 5 const int MAX2=2e6+5;
 6 int n,m;
 7 LL tot,head[MAX1],h[MAX1],adj[MAX2],ad[MAX2],ne[MAX2],next[MAX2];
 8 LL dis[MAX1],a[MAX1];
 9 queue <int> q;
10 bool t[MAX1];
11 inline LL read(){
12     LL an=0,x=1;char c=getchar();
13     while (c<‘0‘ || c>‘9‘) {if (c==‘-‘) x=-1;c=getchar();}
14     while (c>=‘0‘ && c<=‘9‘) {an=an*10+c-‘0‘;c=getchar();}
15     return an*x;
16 }
17 void addedge(LL u,LL v){
18     tot++;
19     adj[tot]=v;    next[tot]=head[u]; head[u]=tot;
20     ad[tot]=u;  ne[tot]=h[v];      h[v]=tot;
21 }
22 void spfa(){
23     int i,j,u,v;
24     LL zt;
25     while (!q.empty()) q.pop();
26     memset(t,false,sizeof(t));
27     for (i=1;i<=n;i++) q.push(i),t[i]=true;
28     while (!q.empty()){
29         u=q.front();q.pop();
30         t[u]=false;zt=a[u];
31         for (i=head[u];i;i=next[i])
32             zt+=dis[adj[i]];
33         if (zt>=dis[u]) continue;
34         dis[u]=zt;
35         for (i=h[u];i;i=ne[i])
36             if (!t[ad[i]])
37                 q.push(ad[i]),t[ad[i]]=true;
38     }
39 }
40 int main(){
41     freopen ("game.in","r",stdin);
42     freopen ("game.out","w",stdout);
43     int i,j;LL x,y;
44     n=read();
45     for (i=1;i<=n;i++){
46         a[i]=read(),dis[i]=read(),x=read();
47         for (j=1;j<=x;j++){
48             y=read();
49             addedge((LL)i,y);
50         }
51     }
52     spfa();
53     printf("%lld",dis[1]);
54     return 0;
55 }