Kupilem ksiazke Stanczyka "Algorytmika Praktyczna" zeby nauczyc sie algorytmow, ale mam problemy ze zrozumieniem kodu. Moglby mi ktos wytlumaczyc kilka linijek zaznaczonych w komentarzu ? Dodam ze wiem co to jest dziedziczenie, szablony itp ale nie rozumie w jakim celu az tak namieszane jest. Gdy implementowal kiedys graf to w ogole nie uzywalem struktur, szablonow tylko sam vector
Oto kod
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
using namespace std;
typedef vector<int> VI;
typedef long long LL;
#define SIZE(x) ((int)(x).size())
#define FOR(x,b,e) for(int x=(b);x<=(e);++x)
#define FORD(x,b,e) for(int x=(b);x>=(e);--x)
#define REP(x,n) for(int x=0;x<(n);++x)
#define PB push_back
#define VAR(v,n) __typeof(n) v = (n) // TEGO NIE ROZUMIE
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
template <class V, class E> struct Graph
{
struct Ed:E // TEGO NIE ROZUMIE
{
int v;
Ed(E p, int w) : E(p),v(w) { } // TEGO NIE ROZUMIE
};
struct Ve : V, vector<Ed> { }; // TEGO NIE ROZUMIE
vector<Ve>g;
Graph(int n=0) : g(n) { };
void Write()
{
REP(x,SIZE(g))
{
cout << x << " : ";
FOREACH(it, g[x]) cout << " " << it->v;
cout << endl;
}
}
void EdgeD(int b, int e, E d = E())
{
g[b].PB(Ed(d,e));
}
};
struct Empty{};
int main()
{
int n,m,b,e;
cin >> n >> m;
Graph<Empty,Empty> gr(n); // TeGO NIE ROZUMIE
REP(x,m)
{
cin >> b >> e;
gr.EdgeD(b,e);
}
gr.Write();
system("pause");
}