//Gang #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #include<cstdlib> #include<cmath> #define FOR(x,y,z) for(int x=y;x<=z;x++) #define REP(x,y,z) for(int x=y;x>=z;x--) #define INF 99999999 #define ll long long ]; ]; ][], n, a, b; int v, u; int temp; using namespace std; int main() { scanf("%d %d %d", &n, &a, &b); FOR(i, , n) FOR(j, , n) { ; else e[i][j] = INF; } FOR(i, , n) { scanf("%d", &v); FOR(j, , v) { scanf("%d", &u); )e[i][u] = ; ; } } FOR(i, , n) { dis[i] = e[a][i]; //book[i] = 0; } book[a] = ; FOR(i, , n - ) { int Min = INF; FOR(j, , n) { && dis[j] < Min) { Min = dis[j]; temp = j; } } book[temp] = ; FOR(h, , n) { if (e[temp][h] != INF && !book[h]) { if (dis[h] > dis[temp] + e[temp][h]) dis[h] = dis[temp] + e[temp][h]; } } } printf(:dis[b]); ; }