![](https://img-blog.csdnimg.cn/20190918140145169.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
图
Rqff
这个作者很懒,什么都没留下…
展开
-
最小生成树Prim&Kruskal算法
题目链接:1258—Agri-NetDescriptionFarmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course. Farmer John ordered a high speed connection for his farm原创 2020-06-24 16:36:59 · 129 阅读 · 0 评论 -
拓扑排序模板
2367-Genealogical tree#include <set>#include <queue>#include <vector>#include <iostream>#include <algorithm> using namespace std;const int MAXN = 110;int main(){ int n; vector<int> adj[MAXN]; //邻接矩阵 int indeg原创 2020-06-24 08:41:17 · 121 阅读 · 0 评论 -
207. 课程表 & 210. 课程表 II (拓扑排序)
207. 课程表拓扑排序的BFS实现class Solution { public boolean canFinish(int numCourses, int[][] prerequisites) { if (numCourses <= 0) { return false; } // 特判 ...原创 2020-02-06 15:51:51 · 145 阅读 · 0 评论 -
1162. 地图分析(BFS)
1162. 地图分析用queue的添加元素时候,用offer不要用addQueue 中 add() 和 offer()都是用来向队列添加一个元素。在容量已满的情况下,add() 方法会抛出IllegalStateException异常,offer() 方法只会返回false做算法题有异常,直接就凉了。Modifier and TypeMethod and Descripti...原创 2020-02-06 10:42:37 · 162 阅读 · 0 评论 -
1306. 跳跃游戏 III
1306. 跳跃游戏 III隐式图问题DFSclass Solution { public boolean canReach(int[] arr, int start) { boolean[] visited = new boolean[arr.length]; return dfs(arr, start, visited); } public boolean dfs(int...原创 2020-02-06 09:38:06 · 176 阅读 · 0 评论 -
841. 钥匙和房间
841. 钥匙和房间分类是图,主要还是搜索吧,用的DFSclass Solution { boolean[] vis; public boolean canVisitAllRooms(List<List<Integer>> rooms) { vis = new boolean[rooms.size()]; vis[0] =...原创 2020-02-05 21:22:58 · 120 阅读 · 0 评论 -
997. 找到小镇的法官
法官是入度为N-1,出度为0的点一开始用了一个num来统计法官的数目,但后来想了一下没有必要,既然有一个法官的入度为N-1了,说明其他的人都信任他,不存在其他人的出度为0public int findJudge(int N, int[][] trust) { int inDegree[] = new int[N + 1]; int outDegree[] = new int[N + 1...原创 2020-02-05 15:53:53 · 201 阅读 · 0 评论