| 19148 | 2025-11-26 16:21:00 | Kristóf | A lehető legkevesebb metróval utazás (40 pont) | cpp17 | Forditási hiba |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> graph;
vector<vector<int>> allomas;
int main()
{
int m,n,s,e;
cin>>m>>n>>s>>e;
allomas.resize(n);
int x,y,z;
vector<vector<int>> adat(m);
for(int i=0;i<m;i++)
{
cin>>x;
for(int j=0;j<x;j++)
{
cin>>y;
allomas[y].push_back(i);
adat[i].push_back(y);
}
}
/*
for(auto x : adat)
{
for(int i=0;i<x.size();i++)
{
cout<<x[i]<<" ";
}
cout<<endl;
}
*/
vector<vector<int>> ans(m+1);
if(allomas[e].size()==0)
{
cout<<-1;
return 0;
}
queue<int> q;
vector<bool> visitedallomas(m,false);
for(auto x : allomas[s])
{
visitedallomas[x]=true;
ans[x].push_back(x);
q.push(x);
}
while(!q.empty())
{
int most=q.top();q.pop();
for(auto x : adat[most])
{
for(auto y : allomas[x])
{
if(y==e)
{
}
if(!visitedallomas[y])
{
visitedallomas[y]=true;
ans[y]=ans[x];
ans[y]
q.push(y);
}
}
}
}
return 0;
}
open /var/local/lib/isolate/439/box/a.out: no such file or directory
main.cpp: In function 'int main()':
main.cpp:52:20: error: 'class std::queue<int>' has no member named 'top'; did you mean 'pop'?
52 | int most=q.top();q.pop();
| ^~~
| pop
main.cpp:65:27: error: expected ';' before 'q'
65 | ans[y]
| ^
| ;
66 | q.push(y);
| ~
main.cpp:65:26: warning: ignoring return value of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; reference = std::vector<int>&; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result]
65 | ans[y]
| ^
In file included from /usr/include/c++/12/vector:64,
from /usr/include/c++/12/functional:62,
from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:71,
from main.cpp:1:
/usr/include/c++/12/bits/stl_vector.h:1121:7: note: declared here
1121 | operator[](size_type __n) _GLIBCXX_NOEXCEPT
| ^~~~~~~~