Loading... #### DFS ```cpp #include<bits/stdc++.h> using namespace std; const int N = 100; int idx, n; int h[N], e[N], ne[N]; bool st[N]; void ins(int a, int b){ e[idx] = b; ne[idx] = h[a]; h[a] = idx++; } void dfs(int u){ st[u] = true; cout << u; 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); cin >> n; int a, b; while(n--){ cin >> a >> b; ins(a, b); } dfs(1); return 0; } ``` Last modification:February 3, 2023 © Allow specification reprint Like 0 如果觉得我的文章对你有用,请随意赞赏
Comment here is closed