# POJ 1847 Tram 最短路

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;

#define MAX 205
#define CLR(arr,v) memset(arr,v,sizeof(arr))

struct nodes
{
int v,d;
bool operator<(const nodes &a) const
{
return d > a.d;
}
}mid;

int h[MAX],dis[MAX],val[MAX*MAX*2],nex[MAX*MAX*2],des[MAX*MAX*2],pos;
bool vis[MAX],inque[MAX];
priority_queue<nodes> q;

void init()
{
pos = 0;   CLR(vis,0);
CLR(h,0);  CLR(val,0);
CLR(nex,0);CLR(des,0);
CLR(inque,0);
fill(dis,dis+MAX,INT_MAX/2);
while(!q.empty()) q.pop();
}

{
val[++pos] = t;
des[pos] = v;
nex[pos] = h[u];
h[u] = pos;
}

int Dijkstra(int n,int b,int e)
{
dis[b] = 0;
mid.d = 0;
mid.v = b;
q.push(mid);
struct nodes p;
while(!q.empty())
{
p = q.top();
q.pop();
if(p.v == e) break;
vis[p.v] = true;
inque[p.v] = false;
for(int i = h[p.v]; i ;i = nex[i])
{
if(!vis[ des[i] ] && dis[p.v] + val[i] < dis[ des[i] ])
{
dis[ des[i] ] = dis[p.v] + val[i];
if(!inque[ des[i] ])
{
mid.v = des[i];
mid.d = dis[ des[i] ];
q.push(mid);
inque[ des[i] ] = true;
}
}
}
}
return dis[e] == INT_MAX/2 ?-1:dis[e];
}

int main()
{
//freopen("1.txt","r",stdin);
int n,s,e;
while(~scanf("%d%d%d",&n,&s,&e))
{
init();
for(int i = 1;i <= n;++i)
{
int t,v;
scanf("%d",&t);
for(int j = 0;j < t;++j)
{
scanf("%d",&v);
}