1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cstring>
5 #include<cmath>
6 #include<cstdlib>
7 #include<vector>
8 using namespace std;
9 typedef long long ll;
10 typedef long double ld;
11 typedef pair<int,int> pr;
12 const double pi=acos(-1);
13 #define rep(i,a,n) for(int i=a;i<=n;i++)
14 #define per(i,n,a) for(int i=n;i>=a;i--)
15 #define Rep(i,u) for(int i=head[u];i;i=Next[i])
16 #define clr(a) memset(a,0,sizeof(a))
17 #define pb push_back
18 #define mp make_pair
19 #define fi first
20 #define sc second
21 #define pq priority_queue
22 #define pqb priority_queue <int, vector<int>, less<int> >
23 #define pqs priority_queue <int, vector<int>, greater<int> >
24 ld eps=1e-9;
25 ll pp=1000000007;
26 ll mo(ll a,ll pp){if(a>=0 && a<pp)return a;a%=pp;if(a<0)a+=pp;return a;}
27 ll powmod(ll a,ll b,ll pp){ll ans=1;for(;b;b>>=1,a=mo(a*a,pp))if(b&1)ans=mo(ans*a,pp);return ans;}
28 void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
29 //void add(int x,int y,int z){ v[++e]=y; next[e]=head[x]; head[x]=e; cost[e]=z; }
30 int dx[5]={0,-1,1,0,0},dy[5]={0,0,0,-1,1};
31 ll read(){ ll ans=0; char last=‘ ‘,ch=getchar();
32 while(ch<‘0‘ || ch>‘9‘)last=ch,ch=getchar();
33 while(ch>=‘0‘ && ch<=‘9‘)ans=ans*10+ch-‘0‘,ch=getchar();
34 if(last==‘-‘)ans=-ans; return ans;
35 }
36 const int N=200005;
37 struct node {
38 ll v; int i;
39 friend bool operator <(node a,node b){
40 return a.v>b.v;
41 }
42 };
43 #include<vector>
44 vector<int> vec_f[N],vec_t[N];
45 #include<queue>
46 priority_queue<node> Q;
47 ll dis[N],s[N],k[N];
48 int r[N],vis[N];
49 int main(){
50 int n=read(),a_;
51 for (int i=1;i<=n;i++){
52 s[i]=read(),k[i]=read(),r[i]=read();
53 for (int j=1;j<=r[i];j++) {
54 a_=read();
55 vec_f[i].pb(a_);
56 vec_t[a_].pb(i);
57 }
58 }
59 for (int i=1;i<=n;i++)
60 dis[i]=k[i],Q.push((node){dis[i],i});
61 while (!Q.empty()){
62 int u=Q.top().i; Q.pop();
63 if (vis[u]) continue;
64 int size=vec_t[u].size();
65 for (int i=0;i<size;i++){
66 int v=vec_t[u][i];
67 if (vis[v]) continue;
68 ll sum=s[v];
69 for (int j=0;j<r[v];j++) sum+=dis[vec_f[v][j]];
70 if (sum<dis[v]){
71 dis[v]=sum; Q.push((node){dis[v],v});
72 }
73 }
74 vis[u]=1;
75 }
76 printf("%lld\n",dis[1]);
77 }