| 20155 | 2026-01-03 12:58:56 | szabelr | A lehető legkevesebb metróval utazás (40 pont) | cpp17 | Compilation error |
// A lehető legkevesebb metróval utazás.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, ind, erk;
cin >> n >> m >> ind >> erk;
vector<vector<int>> adj(n + m + 1);
for (int i = 1; i <= n; i++)
{
int x; cin >> x;
for (int y = 0; y < x; y++)
{
int z; cin >> z;
adj[z].push_back(m + i);
adj[m + i].push_back(z);
}
}
vector<bool> visited(n+m + 1, false);
vector<int> honnan(n+m + 1, -1);
queue<int> q;
q.push(ind);
visited[ind] = true;
while (!q.empty())
{
int v = q.front();
q.pop();
for (int i = 0; i < adj[v].size(); i++)
{
if (!visited[adj[v][i]])
{
honnan[adj[v][i]] = v;
visited[adj[v][i]] = true;
q.push(adj[v][i]);
}
}
}
if (!visited[erk])
cout << -1;
else
{
vector<int> res;
int i = erk;
while (honnan[i] != ind)
{
if(honnan[i]>m)
res.push_back(honnan[i]);
i = honnan[i];
}
cout << res.size() << endl;
reverse(res.begin(), res.end());
for (auto x : res)
cout << x-m << " ";
}
}
// 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
open /var/local/lib/isolate/412/box/a.out: no such file or directory
main.cpp: In function 'int main()':
main.cpp:57:9: error: 'reverse' was not declared in this scope
57 | reverse(res.begin(), res.end());
| ^~~~~~~