day58-graph theory-part08-8.29

2024-08-29 23:04
文章标签 graph theory part08 8.29 day58

本文主要是介绍day58-graph theory-part08-8.29,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

tasks for today:

1. 拓扑排序 117.软件构建

2. dijkstra算法 47.参加科学大会

---------------------------------------------------------------------------------

1. 拓扑排序 117.软件构建

In this practice, it involves mainly the BFS method, which iteratively searching the current graph for current nodes which have the inDegree 0, signifying that it is currently the files that should be taken before proceeding any other files that should be executed based on it. Then after this file is added to the result list, the files it points to has to reduce the inDegree by 1, until all the files are selcted. Or, it will output the -1 signifying there is no doable paln.

from collections import defaultdict, dequedef main():n, m = map(int, input().split())inDegree = [0] * npointTo = defaultdict(list)for _ in range(m):s, t = map(int, input().split())inDegree[t] += 1pointTo[s].append(t)bfsQueue = deque()for i in range(n):if inDegree[i] == 0:bfsQueue.append(i)result = []while bfsQueue:curNode = bfsQueue.popleft()result.append(curNode)curPointTo = pointTo[curNode]if curPointTo:for i in range(len(curPointTo)):inDegree[curPointTo[i]] -= 1if inDegree[curPointTo[i]] == 0:bfsQueue.append(curPointTo[i])if len(result) == n:print(' '.join(map(str, result)))else:print(-1)returnif __name__ == "__main__":main()

2. dijkstra算法 47.参加科学大会

The idea of dijkstra is similar to prim algorithm in day 57.

After going through the entire process, each entry of the minDis records the minimum distance from the start point to current point.

def main():n, m = map(int, input().split())graph = [[float('inf')] * (n+1) for _ in range(n+1)]for _ in range(m):s, e, v  = map(int, input().split())graph[s][e] = vvisited = [False] * (n+1)minDis = [float('inf')] * (n+1)start = 1end = nminDis[1] = 0for i in range(1, n+1):curMin = float('inf')curNode = 1for j in range(1, n+1):if not visited[j] and minDis[j] < curMin:curMin = minDis[j]curNode = jvisited[curNode] = Truefor k in range(1, n+1):if not visited[k] and graph[curNode][k] != float('inf') and minDis[k] > curMin + graph[curNode][k]:minDis[k] = curMin + graph[curNode][k]if minDis[n] == float('inf'): print(-1)else:print(minDis[n])returnif __name__ == "__main__":main()

这篇关于day58-graph theory-part08-8.29的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1119101

相关文章

图神经网络框架DGL实现Graph Attention Network (GAT)笔记

参考列表: [1]深入理解图注意力机制 [2]DGL官方学习教程一 ——基础操作&消息传递 [3]Cora数据集介绍+python读取 一、DGL实现GAT分类机器学习论文 程序摘自[1],该程序实现了利用图神经网络框架——DGL,实现图注意网络(GAT)。应用demo为对机器学习论文数据集——Cora,对论文所属类别进行分类。(下图摘自[3]) 1. 程序 Ubuntu:18.04

SIGMOD-24概览Part7: Industry Session (Graph Data Management)

👇BG3: A Cost Effective and I/O Efficient Graph Database in ByteDance 🏛机构:字节 ➡️领域: Information systems → Data management systemsStorage management 📚摘要:介绍了字节新提出的ByteGraph 3.0(BG3)模型,用来处理大规模图结构数据 背景

A Comprehensive Survey on Graph Neural Networks笔记

一、摘要-Abstract 1、传统的深度学习模型主要处理欧几里得数据(如图像、文本),而图神经网络的出现和发展是为了有效处理和学习非欧几里得域(即图结构数据)的信息。 2、将GNN划分为四类:recurrent GNNs(RecGNN), convolutional GNNs,(GCN), graph autoencoders(GAE), and spatial–temporal GNNs(S

Neighborhood Homophily-based Graph Convolutional Network

#paper/ccfB 推荐指数: #paper/⭐ #pp/图结构学习 流程 重定义同配性指标: N H i k = ∣ N ( i , k , c m a x ) ∣ ∣ N ( i , k ) ∣ with c m a x = arg ⁡ max ⁡ c ∈ [ 1 , C ] ∣ N ( i , k , c ) ∣ NH_i^k=\frac{|\mathcal{N}(i,k,c_{

浪子易支付8.29版本PHP网站源码

源码下载 浪子易支付8.29版本PHP网站源码 更新记录 2024/08/29: 1.付款记录管理支持批量操作 2.优化数据清理功能 3.修复了一些已知问题 2024/07/21: 1.更新全新的V2版API接口,使用RSA公私钥验证 2.支持通过接口发起代付转账、退款、查询等 3.支持通过接口发起付款码支付、JSAPI支付、APP支付 4.订单退款支持多次部分金额退款 5.针对插件开

boost.graph之属性

相关宏 BOOST_INSTALL_PROPERTY #define BOOST_INSTALL_PROPERTY(KIND, NAME) \template <> struct property_kind<KIND##_##NAME##_t> { \typedef KIND##_property_tag type; \} 最终形式为 template <> struct proper

【ZOJ】3874 Permutation Graph 【FFT+CDQ分治】

传送门:【ZOJ】3874 Permutation Graph 题目分析: 容易知道一个个连通块内部的标号都是连续的,否则一定会有另一个连通块向这个连通块建边,或者这个连通块向另一个连通块建边。而且从左到右左边的连通块内最大的标号小于右边连通块内最小的标号。 然后我们可以构造dp方程: dp[n]=n!−i!∗dp[n−i] \qquad \qquad dp[n] = n! - i! *

【HDU】5333 Undirected Graph【LCT+BIT】

传送门:【HDU】5333 Undirected Graph my  code: my~~code: #pragma comment(linker, "/STACK:1024000000")#include <stdio.h>#include <string.h>#include <map>#include <algorithm>using namespace std ;typed

CodeForces 404C Restore Graph

题意: n个点的图  最大度为k  已知从某个点到每个点的距离dis[i]  求  这幅图的边 思路: 告诉了距离  很容易想到dis是从距离为0的那个点开始bfs求出来的 那么复原这幅图的办法就是重新构造这棵bfs形成的树就好了 每层利用点数计算一下是不是违反了最大度k的限制 这里注意  只有dis=0的那个点可以连出k条边  其余的只有k-1条(因为它们还和父亲连着一条边)

LEAN 类型理论之注解(Annotations of LEAN Type Theory)—— 定义上相等(Definitional Equality)

定义上相等(Definitional Equality)指的是意义上相等,即同义,包括了,定义的缩写(Abbreviatory Definition),alpha转换,相同替代(substituting equals for equals)等。下面是LEAN给定的何谓 定义上相等。          注:罗列的推演规则中,如自明其义的,则不多加解析其前提、结果、或特定注解。