树和图的框架
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 10010;
int h[N], e[N], ne[N], idx;
void add(int a, int b) {
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
int main() {
memset(h, -1, sizeof(h));
}
数和图的深度优先遍历
#include<iostream>
#include<algorithm>
using namespace std;
int n, m;
const int N = 10010;
int h[N], e[N], ne[N], idx;
bool st[N];//存遍历过的点
void add(int a, int b) {
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
void dfs(int u) {
st[u] = true;
for (int i = h[u]; i != -1; i = ne[i])
{
int j = e[i];
if (!st[j])dfs(j);
}
}
int main() {
memset(h, -1, sizeof(h));
dfs(1);
}
标签:优先,idx,int,void,ne,dfs,搜索,深度,include
From: https://www.cnblogs.com/windzhao6/p/18330000