首页 > 编程语言 >159.201 算法与结构

159.201 算法与结构

时间:2023-05-19 13:12:34浏览次数:40  
标签:node zero 159.201 算法 team nodes 结构 your must

159.201
159.201 Algorithms & Data Structures
Assignment 6
Write a C++ program that reads a simple (no loops or parallel edges) edge-weighted directed
graph G = (V, E) from standard input, and computes the distance from node zero to all other
nodes. Your code must run in O(n · log n) with n = |V | + |E|. This can be achieved by using
adjacency lists to represent the graph, and by computing distances using Dijkstra’s algorithm
with a heap to identify the next node (with minimum distance) to process.
Input graphs are given in the format
n m
v1 w1 l1
v2 w2 l2
.
.
.
vm wm lm
Here n ≥ 1 and m ≥ 0 denote the number of nodes and edges in the graph, and each of the
following line describes an edge from vi to wi of length li
. All nodes vi
, wi
lie in [0 . . . n), and
li
is a positive integer between 1 and 99. There can be nodes that are unreachable from node
zero. For all other nodes, it is guaranteed that the distance from zero will not exceed 106
.
Your program should print the distances from node zero to all other nodes in ascending order,
separated by a single space. When a node is unreachable, print inf instead. For example:
0 1 2
3 4 5
4
2
99
2
1 3 1 3
Input Output
6 8 0 3 8 2 inf 5
0 1 4
0 3 2
1 2 99
1 5 2
2 5 1
3 1 1
4 1 3
5 2 3
You can use CodeRunner to test your work, but must submit your assignment as usual. If
teamwork is permitted and you work in a team, you must include the names and student IDs
of all team members as comments in your submission, and each team member must submit the
same assignment separately.

 WX:codehelp

标签:node,zero,159.201,算法,team,nodes,结构,your,must
From: https://www.cnblogs.com/messagejava/p/17414810.html

相关文章

  • 为什么 GPU 更适用于时域算法,而 CPU 更适用于频域算法?
    对于懂电脑的人来讲,他们可以简单地区分出电脑的GPU和CPU的应用范畴及其优势,而今天我们要讨论的问题是“为什么GPU更适用于时域算法,而CPU更适用于频域算法?”在讨论这个问题之前,我先带大家来了解一下计算中GPU与CPU架构的区别及并行的处理方式。 1.CPU与GPU架构的......
  • m基于MSER最大稳定极值区域和SVM的交通标志检测识别算法的matlab仿真
    1.算法仿真效果matlab2022a仿真结果如下:       2.算法涉及理论知识概要        在计算机视觉领域,最大稳定极值区域(MSER)(MaximallyStableExtremalRegions)是一种用于在图像中进行斑点检测的方法。这个方法由Matas等人提出,用于在两个不同视角的......
  • m基于MIMO通信系统的半盲信道估计算法matlab仿真,包括QPSK,ML检测,Turbo编译码等
    1.算法仿真效果matlab2022a仿真结果如下:         2.算法涉及理论知识概要        所谓信道估计,就是从接收数据中将假定的某个信道模型的模型参数估计出来的过程。如果信道是线性的话,那么信道估计就是对系统冲激响应进行估计。需强调的是信道......
  • 每天打卡一小时 第三十天 贪心算法
     #include<bits/stdc++.h>usingnamespacestd;intfindContentChildren(vector<int>&children,vector<int>&cookies);intmain(){intn;cin>>n;vector<int>children(n);for(inti=0;i<n;i++)......
  • 邻接表的建立算法
    StatusCreate(ALGraph*G){ inti,j,k; charv1[20],v2[20]; ArcNode*p,*q; printf("请输入顶点数和边数:"); scanf("%d%d",&G->vertices,&G->arcnum); for(i=0;i<G->vexnum;i++) { scanf("%s",G->vertices[i].data)......
  • 数据结构-基本算法复习
    数据结构-基本算法复习第八章排序插入排序直接插入排序:\(O(n^2)\)稳定排序将一条记录插入到已经排序好的有序表中:voidinsertSort(intr[],intlen){for(inti=2;i<=len;i++){if(r[i]<r[i-1]){ intx=r[i];for(in......
  • 排序算法(一):插入排序
    #author:闫振兴#datetime:2020/5/2018:14#software:PyCharm"""文件说明:"""#encoding:utf-8#插入排序:将第一待排序序列第一个元素看做一个有序序列,把第二个元素到最后一个元素当成是未排序序列。#从头到尾依次扫描未排序序列,将扫描到的每个元素插入有序序......
  • 程序流程结构
    概述C语言支持最基本的三种程序运行结构:顺序结构、选择结构、循环结构1.顺序结构:程序按顺序执行,不发生跳转。2.选择结构:依据是否满足条件,有选择地执行相应功能。3.循环结构:依据是否满足条件,循环多次执行某段代码。if语句#include<stdio.h>#include<stdlib.h>intmain()......
  • 树形结构排序1
    CREATETABLE`house_structure`(`id`varchar(32)CHARACTERSETutf8mb4COLLATEutf8mb4_general_ciNOTNULLCOMMENT'房源结构id',`house_name`varchar(50)CHARACTERSETutf8mb4COLLATEutf8mb4_general_ciNOTNULLCOMMENT'房源结构名称',`......
  • Java实现输出九九乘法表—for循环和递归算法
    Java实现输出99乘法表for循环publicclassninenine{publicstaticvoidmain(String[]args){for(inti=1;i<10;i++){for(intj=1;j<=i;j++){System.out.printf("%d*%d=%d\t",j,i,j*i);}......