6126 | 2023-11-02 22:06:02 | MrChipser | A lehető legkevesebb átszállás (50 pont) | cpp11 | Forditási hiba |
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main()
{
int n,m;
cin >> n>>m;
vector<pair<int,int>>jaratok;
vector<int>szam;
vector<int> adj[n];
for(int i = 0; i < n; i++)
{
int a,b;
cin >> a >> b;
//cout << jaratok.size() << endl;
for(int j = 0; j < jaratok.size(); j++)
{
int elso = jaratok[j].first;
int utolso = jaratok[j].second;
//cout << elso << " " << utolso << endl;
if(a-1 >= elso && a-1 <= utolso)
{
adj[j].push_back(i);
//adj[i].push_back(j);
//cout << i<< " " << j << endl;
}
}
//cout << endl;
jaratok.push_back(make_pair(a-1,b-1));
//szam.push_back(i+1);
}
int votma[n] = {0};
int elozo[n];
elozo[0]=-1;
queue<int>q;
q.push(0);
votma[0]=1;
int utolso = -1;
bool vanu = false;
while(!q.empty())
{
int akt = q.front();
q.pop();
for(auto x : adj[akt])
{
if(votma[x]==0)
{
q.push(x);
votma[x]=1;
elozo[x]=akt;
if(jaratok[x].second==m-1 && !vanu)
{
//cout << x << " "
vanu = true;
utolso = x;
}
//cout << akt << " " << x << endl;
}
}
}
if(utols==-1)
{
cout << -1;
return 0;
}
//cout << utolso << endl;
int uthossz = 0;
vector<int>ut;
int x = utolso;
while(x!=-1)
{
ut.insert(ut.begin(),x);
x = elozo[x];
uthossz++;
}
cout << uthossz-1 << endl;
for(int i = 0; i < ut.size(); i++)
cout << ut[i]+1 << " ";
return 0;
}
exit status 1
main.cpp: In function 'int main()':
main.cpp:64:8: error: 'utols' was not declared in this scope; did you mean 'utolso'?
64 | if(utols==-1)
| ^~~~~
| utolso
Exited with error status 1