第一次写bfs, 原理懂了,但是还是写的不明不白
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stdio.h>
#include <queue>
#include <map>
#include <iterator>
#include <string>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
using std::queue;
using std::vector;
#define MaxVex 10000000
struct edge
{
int to; //这条管道的终点
// int Pno;这条管道的编号
int ifV;//出发点是否是阀门, 1:是; 0:不是
};
vector<edge>::iterator it;//定义迭代器it
vector <edge> Graph[MaxVex];//G[count]是一个vector, vecotr里面包含管段信息,G[count]是出发点
void BFS(vector <edge>, int);
void BFS(vector <edge> G, int v)//graph与搜索源节点v
{
int flag[MaxVex] = {0};//所有节点均没有被访问过
queue <int> Q; //与该节点相连接,并且没有被访问过的节点y
vector<edge>::iterator it;
Q.push(v);
while (!Q.empty())
{
v = Q.front();
Q.pop();
for (it = G[v].begin(); it != G[v].end(); it++)//使用迭代器遍历所有G[v]的edge
{
//G[v] vector of edge
if (flag[(*it).to] == 0 && (*it).ifV == 0)
{
cout << "与该点相连的节点编号是 " << (*it).to << endl;
flag[(*it).to] = 1;
Q.push((*it).to);
}
}
}
}
int main()
{
int n, m;//n个顶点,m组数据
scanf("%d%d", &n, &m);
int vex;
while(m--)
{
edge e;
scanf("%d%d%d", &vex, &e.to, &e.ifV);
Graph[vex].push_back(e);//G[1]即表格中第一个点的信息
}
BFS(Graph, 6);
return 0;
}
boomAnalysis.cpp:43:18: error: no member named 'begin' in 'edge'
for (it = G[v].begin(); it != G[v].end(); it++)//使用迭...
~~~~ ^
boomAnalysis.cpp:43:38: error: no member named 'end' in 'edge'
for (it = G[v].begin(); it != G[v].end(); it++)//使用迭...
~~~~ ^
boomAnalysis.cpp:73:2: error: no matching function for call to 'BFS'
BFS(Graph, 6);
^~~
boomAnalysis.cpp:31:6: note: candidate function not viable: no known conversion
from 'vector [10000000]' to 'vector' for 1st argument
void BFS(vector G, int v)//graph与搜索源节点v