当前位置:网站首页>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
边栏推荐
- TestCafe之如何进行调试
- MySQL---子查询
- Made with Flutter and Firebase!counter application
- Handling write conflicts under multi-master replication (3) - Convergence to a consistent state and custom conflict resolution logic
- 【Yugong Series】July 2022 Go Teaching Course 022-Dictionary of Go Containers
- The article you worked so hard to write may not be your original
- Golang 必知必会Go Mod命令
- Golang go-redis cluster模式下不断创建新连接,效率下降问题解决
- cas与自旋锁(轻量级锁就是自旋锁吗)
- MySQL---Basic select statement
猜你喜欢
如何才能真正的提高自己,成为一名出色的架构师?
TestCafe之如何进行调试
1161. Maximum Sum of Elements in Layer: Hierarchical Traversal Application Problems
认识异常 (看完这篇你就懂了)
TestCafe总结
How programmers learn open source projects, this article tells you
Huawei's top engineers lasted nine years "anecdotal stories network protocol" PDF document summary, is too strong
flowable工作流所有业务概念
GateWay实现负载均衡
【NLP】什么是模型的记忆力!
随机推荐
IP protocol from 0 to 1
cas与自旋锁(轻量级锁就是自旋锁吗)
Flink_CDC搭建及简单使用
Cache and Database Consistency Solutions
C# 之 扑克游戏 -- 21点规则介绍和代码实现
All-platform GPU general AI video supplementary frame super-score tutorial
Write a database document management tool based on WPF repeating the wheel (1)
这位985教授火了!当了10年博导,竟无一博士毕业!
架构师04-应用服务间加密设计和实践
2022年Android 面经总结(附含面试题 | 源码 | 面试资料)
Get Douyin Video Details API
Verilog实现占空比为5/18的9分频
手把手教你学会部署Nestjs项目
TestCafe之如何进行调试
MySQL---Create and manage databases and data tables
【Yugong Series】July 2022 Go Teaching Course 022-Dictionary of Go Containers
leetcode 665. Non-decreasing Array
【码蹄集新手村600题】不通过字符数组来合并俩个数字
iNeuOS工业互联网操作系统,设备运维业务和“低代码”表单开发工具
Golang——从入门到放弃