当前位置:网站首页>[hero planet July training leetcode problem solving daily] 17th kuansou
[hero planet July training leetcode problem solving daily] 17th kuansou
2022-07-19 09:21:00 【Seven water Shuliang】
[ Hero planet July training LeetCode Problem solving daily ] The first 17 Japan Wide search
daily
There is only one question today .
subject
One 、2316. Count the logarithm of points that cannot reach each other in an undirected graph
link : 2316. Count the logarithm of points that cannot reach each other in an undirected graph
1. Title Description

2. Thought analysis
- I did it during the weekly match , At that time, we used parallel search .
- Today, we need a wide search , To learn .

3. Code implementation
class Solution:
def countPairs(self, n: int, edges: List[List[int]]) -> int:
g = [[] for _ in range(n)]
for u,v in edges:
g[u].append(v)
g[v].append(u)
visited = [0] * n
def bfs(u):
q = deque([u])
visited[u] = 1
s = 0
while q :
u = q.popleft()
s += 1
for v in g[u]:
if visited[v] == 0:
q.append(v)
visited[v] = 1
return s
ans = 0
for i in range(n):
if visited[i] == 0:
s = bfs(i)
# print(i,s)
ans += s*(n-s)
return ans//2
边栏推荐
- Express
- Etcd database source code analysis -- etcdserver bootstrap recover store from snapshot
- Etcd database source code analysis - initialize etcdserver structure
- es概念模型与基本故障
- Development utility
- [performance optimization methodology series] VI. summary
- Simple third-party component log desensitization
- Project contract analysis from the perspective of Software Engineer
- Google play app store may delete the overview of APP permissions and use a new combination of data security information
- 07---布儒斯特角
猜你喜欢

每日模型系列:2022.07.11

es概念模型与基本故障

C language compilation process

Jsp+servlet+mysql case

Data Lake (20): Flink is compatible with iceberg, which is currently insufficient, and iceberg is compared with Hudi

LDA classifier

C# - this 的用法

Simple third-party component log desensitization

数据湖(二十):Flink兼容Iceberg目前不足和Iceberg与Hudi对比

Flink小知识--任务调度slot的配置 slotSharingGroup
随机推荐
易贝按关键字搜索EBAY商品 API 返回值说明
L2-029 特立独行的幸福
如何正确执行Jedis单元测试
[troubleshooting] common problems and solutions when installing MySQL in Windows system
KNN classifier
Understanding of user / Account / Account
Target detection model size calculation, model complexity (parameter conversion formula)
06---光在介质中的特性
C——指针
C语言基础篇 —— 2-1 指针与野指针
【论文笔记】融合多传感器数据的抓取机械臂末端定位研究
如何在docker里搭建自己的云数据库
How is MySQL data stored on disk?
置顶随笔分类
R语言data.table导入数据实战:data.table使用dcast.data.table函数实现透视表(pivot table)
第五天训练
Resolve the applicationeventmulticast not initialized - call 'refresh' before multicast events exception
Programming in the novel [serial 11] the moon bends in the yuan universe
SAP Fiori 的附件处理(Attachment handling)
岚图梦想家的产品力到底如何?