39322023-03-05 21:38:26SleepyOverlordA lehető legkevesebb átszállás (50 pont)cpp17Time limit exceeded 38/50300ms5544 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

#define IN_FILE "a.in"
#define OUT_FILE "a.out"

template <typename T>
void PR(T var1)
{
	cout << var1 <<endl;
}
template <typename T, typename... Types>
void PR(T var1, Types... var2)
{
	cout << var1;
	PR(var2...);
}

int n, m;
VPII a;
VI dp, p;
set <pair<PII, int> > active;

int main()
{
	cin >> m >> n;
	a.RS(m + 1);
	FOR(i, 1, m) cin >> a[i].X >> a[i].Y;
	int ind = 1;
	while (ind <= m && a[ind].X == 1) 
	{
		active.INS({{a[ind].Y, a[ind].X}, ind});
		++ind;
	}

	dp.RS(n + 1);
	p.RS(n + 1, -1);
	p[1] = 0;
	FOR(i, 2, n)
	{
		dp[i] = m + 1;
		while (!active.empty() && active.BG->X.X < i) active.ER(active.BG);
		for (auto it : active) 
		{
			if (dp[i] > dp[it.X.Y] + 1)
			{
				dp[i] = dp[it.X.Y] + 1;
				p[i] = it.Y;
			}
		}
		while (ind <= m && a[ind].X == i) 
		{
			active.INS({{a[ind].Y, a[ind].X}, ind});
			++ind;
		}
	}

	if (p[n] == -1) 
	{
		PR(-1);
		return 0;
	}
	if (n == 1)
	{
		PR(0);
		return 0;
	}
	PR(dp[n] - 1);
	VI b;
	int i = n;
	while (i > 1)
	{
		b.PB(p[i]);
		i = a[p[i]].X;
	}
	sort(ALL(b));
	for (int x : b) cout << x << " ";

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base38/50
1Accepted0/03ms1684 KiB
2Accepted0/029ms3404 KiB
3Accepted1/13ms2116 KiB
4Accepted1/13ms2280 KiB
5Accepted2/23ms2500 KiB
6Accepted2/23ms2704 KiB
7Accepted2/24ms2852 KiB
8Accepted2/26ms2856 KiB
9Accepted2/28ms3192 KiB
10Accepted2/29ms3364 KiB
11Accepted2/213ms3664 KiB
12Accepted2/216ms3916 KiB
13Accepted2/24ms3596 KiB
14Accepted2/28ms3624 KiB
15Accepted2/29ms3924 KiB
16Accepted2/216ms3924 KiB
17Accepted2/220ms4760 KiB
18Accepted2/224ms5032 KiB
19Accepted2/226ms5116 KiB
20Accepted2/227ms5076 KiB
21Accepted2/228ms5332 KiB
22Accepted2/228ms5544 KiB
23Time limit exceeded0/2300ms4224 KiB
24Time limit exceeded0/2244ms4428 KiB
25Time limit exceeded0/2252ms4472 KiB
26Time limit exceeded0/2244ms4528 KiB
27Time limit exceeded0/2263ms4676 KiB
28Time limit exceeded0/2247ms4836 KiB