48842023-04-05 22:44:12SleepyOverlordA lehető legkevesebb metróval utazás (40 pont)cpp17Runtime error 30/40308ms64220 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

int n, m, source, dest;
vector <USI> a;
VI d;
VPII p;

int main()
{
	cin >> n >> m >> source >> dest;
	a.RS(n + 1);
	FOR(i, 1, n)
	{
		int c;
		cin >> c;
		FOR(j, 1, c) 
		{
			int x;
			cin >> x;
			a[i].INS(x);
		}
	}

	d.RS(m + 1, -1);
	p.RS(m + 1);
	queue<int> fifo;
	fifo.push(source);
	d[source] = 0;
	while (!fifo.empty())
	{
		int node = fifo.front();
		fifo.pop();
		FOR(i, 1, n)
			if (a[i].CNT(node))
			{
				for (int next : a[i])
					if (d[next] == -1)
					{
						d[next] = d[node] + 1;
						p[next] = {node, i};
						if (next == dest) break;
						fifo.push(next);
					}
				if (d[dest] != -1) break;
			}
		if (d[dest] != -1) break;
	}

	cout << d[dest] << endl;
	int node = dest;
	VI sol;
	while (node != source)
	{
		sol.PB(p[node].Y);
		node = p[node].X;
	}
	reverse(ALL(sol));
	for (int x : sol) cout << x << " ";

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base30/40
1Accepted0/03ms1968 KiB
2Accepted0/064ms3492 KiB
3Accepted2/22ms2188 KiB
4Accepted2/22ms2320 KiB
5Accepted2/23ms2636 KiB
6Runtime error0/264ms64220 KiB
7Accepted2/24ms3268 KiB
8Accepted2/24ms3640 KiB
9Accepted2/26ms4336 KiB
10Accepted2/28ms4364 KiB
11Accepted2/24ms3852 KiB
12Accepted2/265ms5192 KiB
13Accepted2/235ms5180 KiB
14Accepted2/261ms4880 KiB
15Runtime error0/2303ms63204 KiB
16Runtime error0/2308ms63028 KiB
17Runtime error0/2300ms62940 KiB
18Runtime error0/2296ms62944 KiB
19Accepted2/232ms4848 KiB
20Accepted2/223ms5180 KiB
21Accepted2/219ms4732 KiB
22Accepted2/234ms5572 KiB