132562025-01-07 11:05:20mateA lehető legkevesebb átszállás (50 pont)cpp17Runtime error 0/5065ms32000 KiB
#include <bits/stdc++.h>
#include <queue>
using namespace std;

vector <vector <pair <int,int>>> graf;
vector <int> tav;
vector <pair <int,int>> parent;

void bfs(int p){
	queue<pair<int,int>> q;
	q.push({p,0});
	tav[p] = 0;
	parent[p] = {1,0};
	while(!q.empty()){
		pair <int,int> csucs = q.front();
		q.pop();
		tav[csucs.first] = tav[parent[csucs.first].first] + 1;
		for(pair <int,int> x : graf[csucs.first]){
			if(tav[x.first] > tav[parent[csucs.first].first] + 1 || tav[x.first] == 0){
				q.push(x);
				parent[x.first] = csucs;
			}
		}
	}
}


int main() {
	cin.tie(0); ios::sync_with_stdio(0);
	int n,m; cin >> n >> m;
	graf.resize(m+1);
	tav.resize(m+1,0);
	parent.resize(m+1);
	for(int i = 0; i < n; i++){
		int a,b; cin >> a >> b;
		for(int j = a+1; j <= b; j++){
			graf[a].push_back({j,i+1});
			//graf[j].push_back({a,i+1});
		}
		
	}
	bfs(1);
	//for(int i = 1; i <= m; i++)
	cout << tav[m]-3 << '\n';
	pair <int,int> p = {m,parent[m].second};
	vector <int> ans;
	while(p.first > 1){
		p = parent[p.first];
		if(p.second == 0){
			break;
		}
		ans.push_back(p.second);
		
	}
	reverse(ans.begin(),ans.end());
	for(auto x : ans){
		cout << x << ' ';
	}
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/01ms316 KiB
2Runtime error0/061ms32000 KiB
3Wrong answer0/11ms316 KiB
4Wrong answer0/11ms316 KiB
5Wrong answer0/21ms316 KiB
6Wrong answer0/21ms316 KiB
7Runtime error0/246ms32000 KiB
8Runtime error0/252ms32000 KiB
9Runtime error0/246ms32000 KiB
10Runtime error0/248ms32000 KiB
11Runtime error0/254ms32000 KiB
12Runtime error0/257ms32000 KiB
13Runtime error0/248ms32000 KiB
14Runtime error0/254ms32000 KiB
15Runtime error0/254ms32000 KiB
16Runtime error0/256ms32000 KiB
17Runtime error0/257ms32000 KiB
18Runtime error0/254ms32000 KiB
19Runtime error0/259ms32000 KiB
20Runtime error0/259ms32000 KiB
21Runtime error0/254ms32000 KiB
22Runtime error0/259ms32000 KiB
23Runtime error0/265ms32000 KiB
24Runtime error0/261ms32000 KiB
25Runtime error0/265ms32000 KiB
26Runtime error0/265ms32000 KiB
27Runtime error0/259ms32000 KiB
28Runtime error0/259ms32000 KiB