3970 2023. 03. 07 07:42:06 CWM A lehető legkevesebb átszállás (50 pont) cpp17 Elfogadva 50/50 6ms 6480 KiB
// Nemes2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <unordered_set>

using namespace std;
int DFS(int a, vector<vector<int>>& graph, int cameFrom) {
	for (size_t i = 0; i < graph[a].size(); i++)
	{
		if (graph[a][i] != cameFrom) {
			DFS(graph[a][i], graph, a);
		}
	}
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int v,m;
	cin >> v >> m;
	vector<pair<int, int>> vonatok;
	vector<pair<int,int>> MaxDist(m+1); //MaxDist, TrainNum
	for (size_t i = 0; i < v; i++)
	{
		int a, b;
		cin >> a >> b;
		vonatok.push_back({ a,b });
		if (MaxDist[a].first < b) MaxDist[a] = { b,i };
	}
	int curMaxDist = 1;
	vector<int> Trains;
	int potMaxDist = -1;
	int potMaxIndex = -1;
	for (size_t i = 0; i < m; i++)
	{
		if (i == curMaxDist) {
			if (potMaxDist <= i) {
				cout << "-1";
				return 0;
			}
			curMaxDist = potMaxDist;
			Trains.push_back(potMaxIndex);
		}
		if (potMaxDist < MaxDist[i+1].first) {
			potMaxDist = MaxDist[i+1].first;
			potMaxIndex = MaxDist[i+1].second;
		}
	}
	cout << Trains.size()-1 << "\n";
	for (size_t i = 0; i < Trains.size(); i++)
	{
		cout << Trains[i] + 1 << " ";
	}
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Részfeladat Összpont Teszt Verdikt Idő Memória
base 50/50
1 Elfogadva 0/0 3ms 1832 KiB
2 Elfogadva 0/0 4ms 3876 KiB
3 Elfogadva 1/1 3ms 2228 KiB
4 Elfogadva 1/1 2ms 2312 KiB
5 Elfogadva 2/2 2ms 2552 KiB
6 Elfogadva 2/2 3ms 2756 KiB
7 Elfogadva 2/2 3ms 3216 KiB
8 Elfogadva 2/2 3ms 3296 KiB
9 Elfogadva 2/2 3ms 3404 KiB
10 Elfogadva 2/2 3ms 3832 KiB
11 Elfogadva 2/2 4ms 4300 KiB
12 Elfogadva 2/2 4ms 4496 KiB
13 Elfogadva 2/2 3ms 4188 KiB
14 Elfogadva 2/2 3ms 4652 KiB
15 Elfogadva 2/2 3ms 4776 KiB
16 Elfogadva 2/2 4ms 4904 KiB
17 Elfogadva 2/2 4ms 5680 KiB
18 Elfogadva 2/2 4ms 5656 KiB
19 Elfogadva 2/2 4ms 5956 KiB
20 Elfogadva 2/2 4ms 6020 KiB
21 Elfogadva 2/2 6ms 6172 KiB
22 Elfogadva 2/2 4ms 6256 KiB
23 Elfogadva 2/2 4ms 5988 KiB
24 Elfogadva 2/2 4ms 5880 KiB
25 Elfogadva 2/2 4ms 6272 KiB
26 Elfogadva 2/2 4ms 6480 KiB
27 Elfogadva 2/2 4ms 6400 KiB
28 Elfogadva 2/2 4ms 6400 KiB