標籤:define ++ == 遍曆 ace 演算法 git return size
嗯..把之前的坑填了吧.(就算)
圖論..就從最基礎的存圖開始吧
先上一波代碼
//#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;}
演算法學習:圖論