鱼C论坛

 找回密码
 立即注册
查看: 3277|回复: 0

路径问题

[复制链接]
发表于 2022-10-23 13:15:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

1.method qadj(i,j) to judge whether thre is a direct path (i.e. edge) from i to j.?example: qadj(2,5) returns True or False
问题1,方法qad判断是否从i到j为直接路径?例如;qadj(2,5) 返回 True 或 False
2.method trypath(path) to verify given path is valid (traversable) or not. Path is given as a list of int?example: trypath([1,2,3,4]) returns True of False
问题2,方法trypath来验证给定路径是否有效?例如;trypath([1,2,3,4])返回True或False

请问这上述两个问题代码如何完善?
  1. class MyGraphMatrix2(MyGraphMatrix):
  2.   def qadj(self,i,j):
  3.     ###CODE ###
  4.   def trypath(self,l):
  5.    ###CODE ###
  6. g = MyGraphMatrix2(5)
  7. g.adj(1,2)
  8. g.adj(1,5)
  9. g.adj(2,1)
  10. g.adj(2,5)
  11. g.adj(2,3)
  12. g.adj(2,4)
  13. g.adj(3,2)
  14. g.adj(3,4)
  15. g.adj(4,2)
  16. g.adj(4,5)
  17. g.adj(4,3)
  18. g.adj(5,4)
  19. g.adj(5,1)
  20. g.adj(5,2)
  21. print(g.adjbody)
  22. print(g.trypath([1,2,5,4,3]))
  23. print(g.trypath([1,3,5,4,3]))
  24. print(g.trypath([1,2,4,3,5]))
  25. print(g.trypath([1,2,4,3,2,5]))
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-26 00:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表