网站首页 站内搜索

搜索结果

查询Tags标签: dist,共有 247条记录
  • luogu P3241 [HNOI2015]开店

    题面传送门 看到这种东西想到差分,即差分成\([1,r]\)减去\([1,l]\)的答案。 距离的式子其实是\(dist_u+dist_v-2*dist_{lca(u,v)}\)前面两项平凡所以要求\(dist_{lca(u,v)}\) 然后这个有经典套路就是每个点往根加和查就是这个式子,直接树剖就好了。 因为强制在线所以可持…

    2021/8/3 23:06:12 人评论 次浏览
  • luogu P3241 [HNOI2015]开店

    题面传送门 看到这种东西想到差分,即差分成\([1,r]\)减去\([1,l]\)的答案。 距离的式子其实是\(dist_u+dist_v-2*dist_{lca(u,v)}\)前面两项平凡所以要求\(dist_{lca(u,v)}\) 然后这个有经典套路就是每个点往根加和查就是这个式子,直接树剖就好了。 因为强制在线所以可持…

    2021/8/3 23:06:12 人评论 次浏览
  • leetcode_743. 网络延迟时间--迪杰斯特拉

    leetcode_743题目描述 题目大意 思路描述 代码 写在最后题目描述 有 n 个网络节点,标记为 1 到 n。 给你一个列表 times,表示信号经过 有向 边的传递时间。 times[i] = (ui, vi, wi),其中 ui 是源节点,vi 是目标节点, wi 是一个信号从源节点传递到目标节点的时间。 现…

    2021/8/3 6:07:38 人评论 次浏览
  • leetcode_743. 网络延迟时间--迪杰斯特拉

    leetcode_743题目描述 题目大意 思路描述 代码 写在最后题目描述 有 n 个网络节点,标记为 1 到 n。 给你一个列表 times,表示信号经过 有向 边的传递时间。 times[i] = (ui, vi, wi),其中 ui 是源节点,vi 是目标节点, wi 是一个信号从源节点传递到目标节点的时间。 现…

    2021/8/3 6:07:38 人评论 次浏览
  • 743. 网络延迟时间(Dijkstra算法)

    Dijkstra算法 public int networkDelayTime(int[][] times, int n, int k) {int max=Integer.MAX_VALUE/2;int[][] g=new int[n][n];for(int i=0;i<n;i++) Arrays.fill(g[i],max);int[] dist=new int[n];Arrays.fill(dist,max);boolean[] vis=new boolean[n];for(int[]…

    2021/8/3 1:06:06 人评论 次浏览
  • 743. 网络延迟时间(Dijkstra算法)

    Dijkstra算法 public int networkDelayTime(int[][] times, int n, int k) {int max=Integer.MAX_VALUE/2;int[][] g=new int[n][n];for(int i=0;i<n;i++) Arrays.fill(g[i],max);int[] dist=new int[n];Arrays.fill(dist,max);boolean[] vis=new boolean[n];for(int[]…

    2021/8/3 1:06:06 人评论 次浏览
  • 743. Network Delay Time[Medium](Leetcode每日一题-2021.08.02)

    Problem You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the target node, and wi is the time it takes for a signal t…

    2021/8/2 23:08:58 人评论 次浏览
  • 743. Network Delay Time[Medium](Leetcode每日一题-2021.08.02)

    Problem You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the target node, and wi is the time it takes for a signal t…

    2021/8/2 23:08:58 人评论 次浏览
  • POJ - 1556 The Doors(计算几何 + 最短路)

    链接 The Doors 题意 从 (0,5)(0,5)(0,5) 位置走到 (10,5)(10,5)(10,5),有 nnn 个垂直于 xxx 轴的墙壁,每个墙壁都会有两个门洞。下面的图片显示出了一个墙体及最短路径。 思路 首先我们把每两个点连一条边,判断边是否和墙体相交,如果不相交就连边,相交就不连; 最后…

    2021/8/2 23:08:52 人评论 次浏览
  • POJ - 1556 The Doors(计算几何 + 最短路)

    链接 The Doors 题意 从 (0,5)(0,5)(0,5) 位置走到 (10,5)(10,5)(10,5),有 nnn 个垂直于 xxx 轴的墙壁,每个墙壁都会有两个门洞。下面的图片显示出了一个墙体及最短路径。 思路 首先我们把每两个点连一条边,判断边是否和墙体相交,如果不相交就连边,相交就不连; 最后…

    2021/8/2 23:08:52 人评论 次浏览
  • Acwing 341. 最优贸易 (spfa 求路径上最大的权差

    添加链接描述 #include<bits/stdc++.h> using namespace std; const int N=1e5+10,M=1e6+10; int n,m,w[N],hs[M],hd[M],e[M],ne[M],idx; int minn[N],maxn[N],vis[N]; void add(int h[],int a,int b){e[idx]=b,ne[idx]=h[a],h[a]=idx++; } void spfa(int dist[],…

    2021/8/1 23:38:19 人评论 次浏览
  • Acwing 341. 最优贸易 (spfa 求路径上最大的权差

    添加链接描述 #include<bits/stdc++.h> using namespace std; const int N=1e5+10,M=1e6+10; int n,m,w[N],hs[M],hd[M],e[M],ne[M],idx; int minn[N],maxn[N],vis[N]; void add(int h[],int a,int b){e[idx]=b,ne[idx]=h[a],h[a]=idx++; } void spfa(int dist[],…

    2021/8/1 23:38:19 人评论 次浏览
  • Prim算法求最小生成树

    Prim算法求最小生成树 给定一个 n 个点 m 条边的无向图,图中可能存在重边和自环,边权可能为负数。 求最小生成树的树边权重之和,如果最小生成树不存在则输出 impossible。 给定一张边带权的无向图 G=(V,E) 其中 V 表示图中点的集合,E表示图中边的集合,n=|V|, m=|E| 由…

    2021/7/31 14:06:00 人评论 次浏览
  • Prim算法求最小生成树

    Prim算法求最小生成树 给定一个 n 个点 m 条边的无向图,图中可能存在重边和自环,边权可能为负数。 求最小生成树的树边权重之和,如果最小生成树不存在则输出 impossible。 给定一张边带权的无向图 G=(V,E) 其中 V 表示图中点的集合,E表示图中边的集合,n=|V|, m=|E| 由…

    2021/7/31 14:06:00 人评论 次浏览
  • leetcode算法题--Perfect Squares

    原题链接:https://leetcode.com/problems/perfect-squares/ int numSquares(int n) { //0点到n点的最短距离queue<int> q;vector<int> dist(n + 1, INT_MAX);q.push(0);dist[0] = 0;while (q.size()) {int t = q.front();q.pop();if(t == n) return dist[n];…

    2021/7/31 11:07:09 人评论 次浏览
扫一扫关注最新编程教程