Update main.cpp#11
Conversation
ylyubimov
left a comment
There was a problem hiding this comment.
В целом классно будет, если ты напишешь какое-то подобие структуры графа.
template <class TVertex, class TEdge>
class Graph {
public:
size_t VerticiesCount() const;
const TVertex& Get(int index) const;
std::vector<std::pair<int, TEdge>> GetNextEdges(int from) const;
std::vector<std::pair<int, TEdge>> GetPrevEdges(int to) const;
};
И алгоритмы уже будешь писать для работы с ним
Подумай не в сторону решения задач, а в сторону создания библиотеки графов)) Раз ты опережаешь всех
| int main() { | ||
| int v_, n; | ||
| std::cin >> v_ >> n; | ||
| vector <int>* adj = new vector <int>[v_]; |
There was a problem hiding this comment.
Пускай это будет уже вектор векторов)
|
Ссылку на контест лучше в комментарии к Пулл реквесту)) |
|
Сказано - сделано:) |
| public: | ||
| Graph(int v): v(v) { adj.assign(v, {}); }; | ||
| void BFS( vector<vector <int> > adj, int src, int dist[], int* paths, int n ); | ||
| int find_shortest_paths( int s, int n, int w ); |
There was a problem hiding this comment.
Не забывай константность методов
| class Graph { | ||
| public: | ||
| Graph(int v): v(v) { adj.assign(v, {}); }; | ||
| void BFS( vector<vector <int> > adj, int src, int dist[], int* paths, int n ); |
There was a problem hiding this comment.
Теперь BFS это метод у него и так есть adj
| }; | ||
|
|
||
| void Graph::BFS( vector<vector <int> > adj, int src, int dist[], int* paths, int n ) { | ||
| bool* visited = new bool[n]; |
There was a problem hiding this comment.
Лучше вектора использовать
| } | ||
|
|
||
| int Graph::find_shortest_paths( int s, int n, int w ) { | ||
| int dist[n]; |
There was a problem hiding this comment.
std::vector(n, INT_MAX)
|
Постарался устранить замечания. |
|
Еще раз закоммитил. Предыдущий раз криво скопировал. |
| #include <assert.h> | ||
| #include <list> | ||
| #include <vector> | ||
| #define INT_MAX 2147483647 |
There was a problem hiding this comment.
Кажется, есть стандартный INT_MAX
There was a problem hiding this comment.
У меня в IDE работает без макроса. Но в Яндекс.Контест без этого не компилируется.
There was a problem hiding this comment.
понятно. Нужно numeric_limits использовать)
| #include <assert.h> | ||
| #include <list> | ||
| #include <vector> | ||
| #define INT_MAX 2147483647 |
There was a problem hiding this comment.
понятно. Нужно numeric_limits использовать)
No description provided.