跳到正文

剪贴板

剪贴板 58yfwqxj

原文
剪贴板信息

剪贴板信息

收录
更新

P1011\color{black}{\text{P1011}}

https://chinese-font.netlify.app/

https://www.bilibili.com/read/cv29466522/?jump_opus=1

http://152.136.110.16:8001/

https://vijos.org/training/59fea890d3d8a10a532d59dd

https://www.luogu.com.cn/paste/o2wxxbva

记得安装雷池

https://twikoo.js.org/

15697

http://152.136.110.16:32771/

我的算法主页:https://www.luogu.com.cn/paste/0dwiarvo

3571863966

10.60.2.21

【置顶】这只蒟蒻不咋水犇,所以粉丝的数量有点少qwq,目前这只蒟蒻在更新学习笔记专栏qwq。

【置顶】一只蒟蒻,害怕被单调队列,拿不到cspj 300分不改主页。

现在在学图论大约把spfa学完了。

准备学习树相关的知识点。

需要练习模拟和其他基础的知识点。

需要练习分治。

码风:

C++
#include <bits/stdc++.h>

using namespace std;
/*
spfa.
*/
#define MAX 100005
#define node int
#define INF 0x7fffffff
vector <long long> edge[MAX], edgeValue[MAX];
long long n, m, minDistance[MAX], visited[MAX];
node start;
int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m >> start;
    for (int i = 1; i <= m; i ++) {
        int from, to, value;
        cin >> from >> to >> value;
        edge[from].push_back(to);
        edgeValue[from].push_back(value);
    }
    //This is input.
    for (int i = 1; i <= n; i ++) minDistance[i] = INF;
    minDistance[start] = 0;
    visited[start] = 1;
    queue <int> nodeQueue;
    nodeQueue.push(start);
    // cout << minDistance[start] << "\n";
    //Push the first node.
    while (!nodeQueue.empty()) {
        int lastNode = nodeQueue.front();
        nodeQueue.pop();
        visited[lastNode] = 0;
        for (int i = 0; i < edge[lastNode].size(); i ++) {
            int nowNode = edge[lastNode][i];
            // cout << lastNode << " " << nowNode << " " << minDistance[nowNode] << " " << minDistance[start] << " \n";
            if (minDistance[nowNode] > minDistance[lastNode] + edgeValue[lastNode][i]) {
                minDistance[nowNode] = minDistance[lastNode] + edgeValue[lastNode][i];
                if (visited[nowNode] == 0) {
                    visited[nowNode] = 1;
                    nodeQueue.push(nowNode);
                }
            }
        }
        //Get the min distance of ${start} and other nodes.
    }
    for (int i = 1; i <= n; i ++) {
        cout << minDistance[i] << " ";
    }
    //Print minDistance.
    return 0;
}