39322023-03-05 21:38:26SleepyOverlordA lehető legkevesebb átszállás (50 pont)cpp17Időlimit túllépés 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base38/50
1Elfogadva0/03ms1684 KiB
2Elfogadva0/029ms3404 KiB
3Elfogadva1/13ms2116 KiB
4Elfogadva1/13ms2280 KiB
5Elfogadva2/23ms2500 KiB
6Elfogadva2/23ms2704 KiB
7Elfogadva2/24ms2852 KiB
8Elfogadva2/26ms2856 KiB
9Elfogadva2/28ms3192 KiB
10Elfogadva2/29ms3364 KiB
11Elfogadva2/213ms3664 KiB
12Elfogadva2/216ms3916 KiB
13Elfogadva2/24ms3596 KiB
14Elfogadva2/28ms3624 KiB
15Elfogadva2/29ms3924 KiB
16Elfogadva2/216ms3924 KiB
17Elfogadva2/220ms4760 KiB
18Elfogadva2/224ms5032 KiB
19Elfogadva2/226ms5116 KiB
20Elfogadva2/227ms5076 KiB
21Elfogadva2/228ms5332 KiB
22Elfogadva2/228ms5544 KiB
23Időlimit túllépés0/2300ms4224 KiB
24Időlimit túllépés0/2244ms4428 KiB
25Időlimit túllépés0/2252ms4472 KiB
26Időlimit túllépés0/2244ms4528 KiB
27Időlimit túllépés0/2263ms4676 KiB
28Időlimit túllépés0/2247ms4836 KiB