stl真是好,,偷懒少写邻接表,, 两个STL应用使代码简短了很多.然而还是那句话,天上不会掉馅饼,程序的效率还是有所下降的.然而,效率不是全部,人们宁可牺牲三倍效率用Java而不用C语言就是最好的例子(from_Charles E Leiserson_),具体取舍要看情况. ——摘自luogu dalao #include <cstdio> #include <algorithm> #include <iostream> #include <vector>…
题目链接:https://www.luogu.org/problemnew/show/P3371#sub 堆优化迪杰斯特拉,留着以后复习用 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <queue> using namespace std; ; ; struct Edge{ int u,v,w; }e[maxn]; s…
题目链接:https://www.luogu.org/problemnew/show/P3371 我永远都喜欢Flyod.dijkstra + heap.SPFA #include <cstdio> #include <cstring> #include <queue> #include <algorithm> using namespace std; ; const int inf = 0x7fffffff; int n, m, s, dis[maxn];…
无优化:500ms deque优化:400ms #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 550000; const int inf = 0x7fffffff; int dis[maxn], n, m, s; bool vis…
Luogu P3371 单源最短路径 题目描述 如题,给出一个有向图,请输出从某一点出发到所有点的最短路径长度. 输入输出格式 输入格式: 第一行包含三个整数N.M.S,分别表示点的个数.有向边的个数.出发点的编号. 接下来M行每行包含三个整数Fi.Gi.Wi,分别表示第i条有向边的出发点.目标点和长度. 输出格式: 一行,包含N个用空格分隔的整数,其中第i个整数表示从点S出发到点i的最短路径长度(若S=i则最短路径长度为0,若从点S无法到达点i,则最短路径长度为2147483647) 输入输出…
单源最短路(dijkstra算法及堆优化) 弱化版题目链接 n^2 dijkstra模板 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ]; ]; struct Node{ int to; int w; Node *next; } node[]; Node *head[]; int main() { scanf(&q…
Floyd Floyd 本质上类似一种动态规划,dp [ i ] [ j ] = dp [ i ] [ k ] + dp[ k ] [ j ]. /** * Night gathers, and now my watch begins. * It shall not end until my death. * I shall take no wife, hold no lands, father no children. * I shall wear no crowns and win no g…
本来我写的对的 我就多手写了个 ios::sync_with_stdio(false); 我程序里面用了cin 还有scanf 本来想偷偷懒 我就说 我查了半天错 根本找不到的啊... 后来交了几次 发现一直有RE 才发现...... 我好笨 //最短路 dijkstral #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ; typedef pair<ll ,int> pli; struct…
随手一打就是标准的SPFA,默认1号节点为出发点,当然不用 f 判断是否在队里也可以,只是这样更优化一点 void spfa() { int i,x,k; ;i<=n;i++) { d[i]=oo; f[i]=; } d[]=; q.push(); while (!q.empty()) { x=q.front(); q.pop(); f[x]=; for (i=first[x];i;i=next[i]) { k=v[i]; if (d[k]>d[x]+w[i]) { d[k]=d[x]+w[i…
https://www.luogu.org/problem/show?pid=3371 题目描述 如题,给出一个有向图,请输出从某一点出发到所有点的最短路径长度. 输入输出格式 输入格式: 第一行包含三个整数N.M.S,分别表示点的个数.有向边的个数.出发点的编号. 接下来M行每行包含三个整数Fi.Gi.Wi,分别表示第i条有向边的出发点.目标点和长度. 输出格式: 一行,包含N个用空格分隔的整数,其中第i个整数表示从点S出发到点i的最短路径长度(若S=i则最短路径长度为0,若从点S无法到达点i…