# 基礎圖論 ## 建圖 ## DFS & BFS dfs程式碼 ```cpp= bool vist[100005]; vector<int> v[100005]; void dfs(int n){ vist[n]=1; for(auto e:v[n]){ if(!vist[e])dfs(e); } } ``` bfs程式碼 ```cpp= bool vist[100005]; vector<int> v[100005]; void bfs(int n){ queue<int> qu; qu.push(n); vist[n]=1; while(!qu.empty()){ int u=qu.top(); qu.pop(); for(auto e:v[u]){ if(!vist[e]){ vist[e]=1; qu.push(e); } } } } ``` ## 習題 ###### tags: `APCS與競賽入門`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up