当前位置:网站首页>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 ansSummary
Graph Theory + Max Ring + Inward Basis Ring + Timestamp
边栏推荐
猜你喜欢
随机推荐
leetcode 665. Non-decreasing Array 非递减数列(中等)
Given an ip address, how does the subnet mask calculate the network number (how to get the ip address and subnet mask)
2022年Android 面经总结(附含面试题 | 源码 | 面试资料)
A common method and the use of selenium
Three.js入门
The article you worked so hard to write may not be your original
MySQL---aggregate function
几款永久免费内网穿透,好用且简单(内网穿透教程)
Chinese encoding Settings and action methods return values
Go record - slice
GAC Honda Safety Experience Camp: "Danger" is the best teacher
多线程之锁
ECCV 2022 华科&ETH提出首个用于伪装实例分割的一阶段Transformer的框架OSFormer!代码已开源!...
AcWing 1282. Search Keyword Problem Solution ((AC Automata) Trie+KMP)+bfs)
All-platform GPU general AI video supplementary frame super-score tutorial
MySQL common statements
ThreadLocal
[TypeScript] OOP
1161. Maximum Sum of Elements in Layer: Hierarchical Traversal Application Problems
每日练习------随机产生一个1-100之间的整数,看能几次猜中。要求:猜的次数不能超过7次,每次猜完之后都要提示“大了”或者“小了”。









