Well.. Fill in the pits before. (even)
Graph theory: Let's start with the most basic map.
First, a wave of code.
//#define fre yes#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 100005;bool Vis[maxn];int head[maxn];int ver[maxn];int to[maxn];int n,m;template<typename T>inline void read(T&x){ x = 0;char c;int lenp = 1; do { c = getchar();if(c == '-') lenp = -1; } while(!isdigit(c)); do { x = x * 10 + c - '0';c = getchar(); } while(isdigit(c)); x *= lenp;}void addedge(int x,int y){ ver[tot] = y; to[tot] = head[x]; head[x] = tot++;}void kre(int x){ for (int i=head[x];~i;i=to[i]) { int y = ver[i];//下一条边 if(Vis[y]) kre(y); }}int main(){ memset(head,-1,sizeof(head)); read(n);read(m); for (int i=1;i<=m;i++) { int x,y; addedge(x,y); } //遍历每一条边 for (int i=1;i<=n;i++) kre(i); return 0;}
Algorithmic Learning: Graph theory