Re: [闲聊] 每日leetcode

楼主: Rushia (みけねこ的鼻屎)   2024-06-30 16:22:07
※ 引述《smart0eddie (smart0eddie)》之铭言:
: 2024-06-30
: 1579. Remove Max Number of Edges to Keep Graph Fully Traversable
: Alice and Bob have an undirected graph of n nodes and three types of edges:
: Type 1: Can be traversed by Alice only.
: Type 2: Can be traversed by Bob only.
: Type 3: Can be traversed by both Alice and Bob.
: Given an array edges where edges[i] = [typei, ui, vi] represents a bidirectional edge of type typei between nodes ui and vi, find the maximum number of edges you can remove so that after removing the edges, the graph can still be fully traversed by both Alice and Bob. The graph is fully traversed by Alice and Bob if starting from any node, they can reach all other nodes.
: Return the maximum number of edges you can remove, or return -1 if Alice and Bob cannot fully traverse the graph.
思路:
1.照着提示做,连通检查用并查集,先把type3的边分别给alice和bob,如果两边的点没有
连通,用过的边数+1。
2.处理剩下的两种类型边,如果两点已经连通就忽略,否则用过的边数+1。
3.检查alice和bob是否是连通图,不是返回-1。
4.因为我们先用type3的边再用type2和type1,所以只要图形连通就会自动删除两点之间
存在type3和其他两种的边,也就是会使用最少且连通的边数,假定为 n,最多可以删
除的边数为: 总边数-n(用过的边)
java code
作者: sustainer123 (caster)   2024-06-30 16:23:00
大师
作者: oin1104 (是oin的说)   2024-06-30 16:23:00
我今天放弃 我去看解答 看那个什么union find 有够靠北谁想得到
作者: DJYOMIYAHINA (通通打死)   2024-06-30 16:23:00
看题目直接放弃 晚点再来看一次==我看了答案说union find就回去想 还是没想到 我就这样了
作者: sustainer123 (caster)   2024-06-30 16:26:00
我图学得超烂 对不起

Links booklink

Contact Us: admin [ a t ] ucptt.com