首页 > 其他 > 详细

[LintCode] Connecting Graph

时间:2017-11-12 10:29:12      阅读:296      评论:0      收藏:0      [点我收藏+]

Given n nodes in a graph labeled from 1 to n. There is no edges in the graph at beginning.

You need to support the following method:

1. connect(a, b), add an edge to connect node a and node b. 2.query(a, b)`, check if two nodes are connected

Example

5 // n = 5
query(1, 2) return false
connect(1, 2)
query(1, 3) return false
connect(2, 4)
query(1, 4) return true



[LintCode] Connecting Graph

原文:http://www.cnblogs.com/lz87/p/7500092.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!