当前位置:网站首页>leetcode: 6135. The longest ring in the graph [inward base ring tree + longest ring board + timestamp]
leetcode: 6135. The longest ring in the graph [inward base ring tree + longest ring board + timestamp]
2022-07-31 18:32:00 【Looking Back at the White Speed Dragon King】
Analysis
The out-degree of each point is at most 1
So it is a [weakened] inward basis ring graph
All connected components have at most one ring
All points have at most one ring
The way of using timestampRecord the time of the last visit of each point
If there are repeated visits and the start time is after st, it means a new ring
Record it in the record
At the same time update the timestamp, and this pointThe most recent timestamp is sufficient
ac code
class Solution:def longestCycle(self, edges: List[int]) -> int:# At most one outgoing edge -> weaken the inward base ring tree# Each Unicom component has at most one ring# Each point has at most one ring# Timestamp + optimization while traversingn = len(edges)time = [0] * nclock, ans = 1, -1# x is the starting pointfor x, t in enumerate(time):if t: continue # has been passively traversed beforest = clockwhile x >= 0:if time[x]: # Second traversal xif time[x] >= st: # find a new ringans = max(ans, clock - time[x])breaktime[x] = clockclock += 1x = edges[x]return ans
Summary
Graph Theory + Max Ring + Inward Basis Ring + Timestamp
边栏推荐
猜你喜欢
GAC Honda Safety Experience Camp: "Danger" is the best teacher
Go1.18升级功能 - 模糊测试Fuzz 从零开始Go语言
九齐ny3p系列语音芯片替代国产方案KT148A性价比更高420秒长度
Kotlin协程:续体、续体拦截器、调度器
iNeuOS工业互联网操作系统,设备运维业务和“低代码”表单开发工具
Combinatorics Notes (6) Associative Algebra of Locally Finite Partially Ordered Sets, Möbius Inversion Formula
TestCafe总结
1161. Maximum Sum of Elements in Layer: Hierarchical Traversal Application Problems
Apache EventMesh 分布式事件驱动多运行时
1161. 最大层内元素和 : 层序遍历运用题
随机推荐
JD.com searches for products by keyword API
Made with Flutter and Firebase!counter application
MySQL---排序与分页
Tkinter 入门之旅
2022 Android interview summary (with interview questions | source code | interview materials)
Routing interception of WeChat applet
10 Ways to Keep Your Interface Data Safe
How can we improve the real yourself, become an excellent architect?
无主复制系统(2)-读写quorum
Masterless replication system (2) - read and write quorum
Golang 小数操作之判断几位小数点与四舍五入
【PIMF】OpenHarmony 啃论文俱乐部—盘点开源鸿蒙三方库【3】
ThreadLocal
Given an ip address, how does the subnet mask calculate the network number (how to get the ip address and subnet mask)
几款永久免费内网穿透,好用且简单(内网穿透教程)
AcWing 1282. 搜索关键词 题解((AC自动机)Trie+KMP)+bfs)
MySQL---子查询
全平台GPU通用AI视频补帧超分教程
2022年Android 面经总结(附含面试题 | 源码 | 面试资料)
How to change npm to Taobao mirror [easy to understand]