首页 > 编程语言 >48024 python 代码分析

48024 python 代码分析

时间:2023-05-17 13:24:36浏览次数:39  
标签:node 48024 format python 代码 arcs digraph input line


Computer Science 220SC (2023)
Assignment 3 (Basic graph algorithms and traversals)
See Canvas for due date
This assignment requires you to submit programs in Python that you have written yourself
to the automarker, https://www.automarker.cs.auckland.ac.nz. Your implementation
must be from first principles and cannot use an existing library methods that might solve
the problem (eg performs graph operations etc).
The automarker runs on a Linux box. Read the automarker help and FAQ for more
details.
Please submit only Python source code (.py or .py3 extensions only).
1. Delete a node from a digraph and record number of arcs removed 30 Marks
For each digraphs in a set of digraphs given as adjacency lists, read in the digraph,
delete the node with index n − 3 where n is the order of the digraph, and write the
digraph back to the terminal. After the adjacency lists, write out how many arcs
have been removed in 代做48024 python  the process. Assume input digraphs have order at least 3.
Input format: described below under the heading “Digraph input format”.
Output format: the same as the input format but with one extra line after each
digraph stating the number of arcs that were removed when the node was removed.
Ensure that you maintain the node naming conventions.
For the example input shown below, the first digraph would have node with index
1 removed, and the second graph would have node index 0 removed, so the output
would be
Here the first line indicates the order of the new digraph is 3, the next three lines
are the three adjacency lists showing the arcs of the this digraph, and the 3 on line
5 indicates that three arcs were removed from the input digraph. The next line has
a 2 indicating that the next digraph has order 2 and so on.
1
2. Back and cross arcs in a DFS 30 Marks
For a given set of digraphs, write a program that performs DFS on each digraph
starting at node 0 and prints out the total number of back arcs and cross arcs resulting
from the traversal. Use our standard convention that when there is a choice of white
or grey nodes, the one with the lowest index should be chosen.
Input format: described below under the heading, “Digraph input format”.
Output format: For each input digraph, print out a line with the number of back
arcs, then whitespace, and then the number of cross arcs.
For the example input shown below, the output would be
1 0
0 1
3. BFS to find distances 30 Marks
Write a program that performs BFS on each of a given set of digraphs starting at
node 1 and prints the distance to the most distant node from 1 and reports the node
with the highest index at that distance. Nodes that are not reachable from 1 have
an undefined distance and should be ignored.
Input format: described below under the heading, “Digraph input format”.
Output format: For each input digraph, print out a line with the distance to the
most distant node, then a space, then the highest index of a node at that distance.
Ignore nodes that are not reachable from 1.
For the example input shown below, the output would be
2 0
0 1
2
Digraph input format
A sequence of one or more digraphs is taken from the standard input (eg sys.stdin). Each
graph is represented by an adjacency list. The first line is an integer n indicating the order
of the graph. This is followed by n white space separated lists of adjacencies for nodes
labeled 0 to n - 1. The lists are sorted. The input will be terminated by a line consisting
of one zero (0). This line should not be processed. The sample input below shows two
digraphs, the first has node set {0, 1, 2, 3} and arc set {(0, 1),(0, 3),(1, 2),(1, 3),(2, 0)}, the
second has node set {0, 1, 2} and arc set {(0, 1),(0, 2),(2, 1)}.
Marking
The maximum number of submissions for each problem is fixed at 12.
Each problem has 3 test cases associated with it worth one third of the marks for that
problem. Some of the test cases will be large. You get full marks if you pass all test
cases.

  WX:codehelp

标签:node,48024,format,python,代码,arcs,digraph,input,line
From: https://www.cnblogs.com/messagejava/p/17408371.html

相关文章

  • 【Python】Centos7安装dirsearch
    一、升级Openssl1.1.1 1、官网下载源码:https://www.openssl.org/2、安装#./config--prefix=/datas/soft/openssl-1.1.1no-zlib#make#makeinstall3、新版配置#ln-s/datas/soft/openssl-1.1.1/include/openssl/usr/include/openssl#ln-s/datas/soft/openss......
  • < Python全景系列-3 > Python控制流程盘点及高级用法、神秘技巧大揭秘!
    欢迎来到我们的系列博客《Python全景系列》!在这个系列中,我们将带领你从Python的基础知识开始,一步步深入到高级话题,帮助你掌握这门强大而灵活的编程语法。无论你是编程新手,还是有一定基础的开发者,这个系列都将提供你需要的知识和技能。 这是系列第三篇,在这篇文章中我们将全面深......
  • JAVA实现html代码转为图片
    方法一:html2Image1、引入依赖<dependency><groupId>gui.ava</groupId><artifactId>html2image</artifactId><version>2.0.1</version></dependency>2、代码实现@ComponentpublicclassHtmlUtil{/***......
  • python 使用企业微信发邮件加加图形化界面
    importsysfromPyQt5.QtWidgetsimportQApplication,QWidget,QLabel,QLineEdit,QTextEdit,QPushButtonimportrequests,base64,hashlibimportsmtplibimportosimportglobfromemail.mime.textimportMIMETextfromemail.mime.multipartimportMIMEMultipa......
  • generate a 3D chart in Python using the CSV data
    Here's an example of how you could use Matplotlib to create a 3D scatter plot from your CSV data:   importpandasaspdimportmatplotlib.pyplotaspltfrommpl_toolkits.mplot3dimportAxes3D#LoadtheCSVdataintoaPand......
  • Git 代码分支管理 | 京东云技术团队
    作者:京东科技周新智一、引言近日,IoT研发团队加入了不少新同学,对git分支的命名和管理方式有些许的模糊,分支的命名规范以及管理方式对项目的版本发布至关重要,为了解决实际开发过程中版本发布时代码管理混乱、冲突等比较头疼的问题,我们将在文中阐述如何更好的管理代码分支。二、总......
  • 其实,领域认知比会写代码更重要!
    大家好,我是飘渺!按照惯例,首先声明,以下内容皆为个人观点。但,无论你是经验丰富的专业人士还是刚刚入行的小白,都希望下面这些见解能够给你带来一些帮助。我从2022年年中就想写这篇文章了,但很多观点我一时无法全部记住。所以在过去的一年里,我一直在收集想法并把它们记录下来,现在我有了足......
  • 在gitlab上,把旧项目的分支代码,转移到新项目里,Git命令语句
    1clone老项目#gitclonegit@xxxx/demo.git2进入到demo目录#cddemo3移除老项目的地址替换成新项目#gitremoteset-url--pushorigingit@xxx/account.git4将镜像推到远程#gitpush-uoriginmaster ......
  • git回滚代码
    1、未提交未提交有以下两种情况:1)已经在工作区修改了文件,但还未执行gitadd提交到暂存区。2)已经执行了gitadd提交到暂存作,但还未执行gitcommit提交本地仓库。这时候回退:gitreset--hard这样等于清空了暂存区和工作区,本地仓库回退到了最新的提交状态。2、已提交未推送......
  • 行政区划代码(使用国务院官方数据)形成树形结构数据表
    2022年中华人民共和国行政区划代码https://www.mca.gov.cn/article/sj/xzqh/1980/202304/20230400047341.shtml  下拉复制粘贴到excel,导入数据库表结构为:CREATETABLE`citynew`(`id`int(10)unsignedNOTNULLAUTO_INCREMENT,`pre_id`int(11)DEFAULTNULL,`......