| 18970 | 2025-11-13 19:32:16 | Kristóf | Fertőzési sorozat (50 pont) | cpp17 | Forditási hiba |
#include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;
vector<vector<int>> graph;
vector<int> sorozat;
bool bfs(int s,int n,int k)
{
vector<bool> visited(n,false);
queue<int> q;
map<int,int> dist;
q.push(s);
visited[s]=true;
dist[s]=0;
map<int,int> db;
while(!q.empty())
{
int u=q.front();q.pop();
for(int x : graph[u])
{
if(!visited[x])
{
dist[x]=dist[u]+1;
visited[x]=true;
q.push(x);
db[dist[x]]++;
}
}
}
bool elso=true;
for(int i=1;i<k;i++)
{
if(dist[sorozat[i]] == dist[sorozat[i-1]])
continue;
else if (dist[sorozat[i]]-1 != dist[sorozat[i-1]] && (!elso && db[dist[x]] !=0))
return false;
else elso=false;
}
return true;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n,m,k;
cin>>n>>m>>k;
graph.resize(n+1);
sorozat.resize(k);
int x,y;
for(int i=0;i<k;i++)
{
cin>>sorozat[i];
}
for(int i=0;i<m;i++)
{
cin>>x>>y;
graph[x].push_back(y);
graph[y].push_back(x);
}
//sorozat.push_back(-1);
vector<int> ans;
for(int i=1;i<=n;i++)
{
if(bfs(i,n,k))
{
//cout<<endl;
ans.push_back(i);
}
//cout<<endl;
}
cout<<ans.size()<<endl;
for(auto x : ans)
{
cout<<x<<" ";
}
return 0;
}
open /var/local/lib/isolate/419/box/a.out: no such file or directory
main.cpp: In function 'bool bfs(int, int, int)':
main.cpp:40:76: error: 'x' was not declared in this scope
40 | else if (dist[sorozat[i]]-1 != dist[sorozat[i-1]] && (!elso && db[dist[x]] !=0))
| ^