/* 思路就是遍历所有人,对于每一个人,寻找他的好友,找到好友后再找这个好友的好友 ,这样深度优先遍历下去,设置一个flag记录是否已经遍历了这个人. 其实dfs真正有用的是flag这个变量,因为如果m个人最多m个朋友圈,设置后flag后,相同的朋友圈会 检测到flag就会不算数. */ public int findCircleNum(int[][] M) { int m = M.length; if (m==0) return 0; int res = 0; boolean[] flag =…
There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, then A is an indirect friend of C. And we defined a fri…
题目: https://leetcode.com/problems/friend-circles/ There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, then…
班上有 N 名学生.其中有些人是朋友,有些则不是.他们的友谊具有是传递性.如果已知 A 是 B 的朋友,B 是 C 的朋友,那么我们可以认为 A 也是 C 的朋友.所谓的朋友圈,是指所有朋友的集合.给定一个 N * N 的矩阵 M,表示班级中学生之间的朋友关系.如果M[i][j] = 1,表示已知第 i 个和 j 个学生互为朋友关系,否则为不知道.你必须输出所有学生中的已知的朋友圈总数.示例 1:输入: [[1,1,0], [1,1,0], [0,0,1]]输出: 2 说明:已知学生0和学生1互…
There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, then A is an indirect friend of C. And we defined a fri…
[抄题]: There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, then A is an indirect friend of C. And we defined…
问题描述 在一个班级里有N个同学, 有些同学是朋友,有些不是.他们之间的友谊是可以传递的比如A和B是朋友,B和C是朋友,那么A和C也是朋友.我们定义 friend circle为由直接或者间接都是朋友组成的group. 给定N*N 数组 M 代表同学之间的关系. 如果M[i][j] = 1, 那么i 和 j 同学是朋友,现在我们需要输出friend circles 的数量 Example 1: Input: [[1,1,0], [1,1,0], [0,0,1]] Output: 2 解释: 0和…
2366 朋友圈 2012年省队选拔赛河北  时间限制: 10 s  空间限制: 256000 KB  题目等级 : 大师 Master     题目描述 Description 在很久很久以前,曾经有两个国家和睦相处,无忧无虑的生活着. 一年一度的评比大会开始了,作为和平的两国,一个朋友圈数量最多的永远都是最值得他人的尊敬,所以现在就是需要你求朋友圈的最大数目. 两个国家看成是 AB 两国,现在是两个国家的描述: 1. A 国:每个人都有一个友善值,当两个 A 国人的友善值 a.b,如果 a…
Description 在很久很久以前,曾经有两个国家和睦相处,无忧无虑的生活着.一年一度的评比大会开始了,作为和平的两国,一个朋友圈数量最多的永远都是最值得他人的尊敬,所以现在就是需要你求朋友圈的最大数目. 两个国家看成是AB两国,现在是两个国家的描述: 1.         A国:每个人都有一个友善值,当两个A国人的友善值a.b,如果a xor b mod 2=1, 那么这两个人都是朋友,否则不是: 2.         B国:每个人都有一个友善值,当两个B国人的友善值a.b,如果a xor…
2744: [HEOI2012]朋友圈 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 612  Solved: 174[Submit][Status][Discuss] Description 在很久很久以前,曾经有两个国家和睦相处,无忧无虑的生活着.一年一度的评比大会开始了,作为和平的两国,一个朋友圈数量最多的永远都是最值得他人的尊敬,所以现在就是需要你求朋友圈的最大数目. 两个国家看成是AB两国,现在是两个国家的描述: 1.         …