4.1 Route Between Nodes
来源:互联网 发布:2017最新网络热门话题 编辑:程序博客网 时间:2024/05/23 18:04
For all directed graph problem, I use struct DirectedGraphNode:
struct DirectedGraphNode { int label; vector<DirectedGraphNode *> neighbors; DirectedGraphNode(int x) : label(x) {}; };
Simply BFS traverse Graph:
bool hasRoute(vector<DirectedGraphNode*> graph, DirectedGraphNode* s, DirectedGraphNode* t) { // write your code here queue<DirectedGraphNode*> q; q.push(s); while(!q.empty()){ DirectedGraphNode* cur = q.front(); q.pop(); for(auto node : cur->neighbors) q.push(node); if(cur == t) return true; } return false; }
Note: BFS always first think about queue!
0 0
- 4.1 Route Between Nodes
- lintcode:Route Between Two Nodes in Graph
- DFS-----Route Between Two Nodes in Graph
- #176 Route Between Two Nodes in Graph
- Route Between Two Nodes in Graph
- Route Between Two Nodes in Graph
- Lintcode176 Route Between Two Nodes in Graph solution 题解
- 176.Route Between Two Nodes in Graph-图中两个点之间的路线(中等题)
- The basic difference between Route and Bridge
- Find the distance between two nodes
- Finding Path/Route Between two points on MapKit in iPhone
- passwordless SSH connectivity not set up between the following nodes
- find distance between two nodes in a binary tree
- Route
- Route
- route
- route
- Route
- 如何让vnc界面和windows之间互相拷贝
- Django Admin:添加富文本编辑器kindeditor
- linux两个不同终端上的信息交流
- 使用PL/SQL插入大量数据
- 如何生成随机数(上)
- 4.1 Route Between Nodes
- leetcode 273 : Integer to English Words
- URL转Drawable之 Android中获取网络图片的三种方法
- linux LVM
- SDWebImage的一些小东西
- 2015_10_26
- 分清EMC EMI EMS有何不同?
- Android 属性动画ValueAnimator和ObjectAnimator的高级用法
- TextView设置setCompoundDrawables或setCompoundDrawablesWithIntrinsicBounds区别