首页 > 其他分享 >1129.热浪

1129.热浪

时间:2023-10-24 17:27:24浏览次数:27  
标签:1129 ch dist int 热浪 vis include id

最短路模板题

#include <stdio.h>
#include <stdlib.h>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#define R(x) x = read()
using namespace std;
typedef pair<int, int> PII;

const int N = 2510, M = 12410;

int n, m, s, t;
int h[N], ne[M], e[M], w[M], idx;
int dist[N];
bool vis[N];

inline int read()
{
    int x = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9')
        ch = getchar();
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x;
}

inline void add(int a, int b, int c)
{
    ne[++idx] = h[a];
    e[idx] = b;
    w[idx] = c;
    h[a] = idx;
}

void Dijkstra(int s, int t)
{
    priority_queue<PII, vector<PII>, greater<PII>> q;
    memset(dist, 0x3f, sizeof dist);
    dist[s] = 0;
    q.push({0, s});
    while(!q.empty())
    {
        auto tmp = q.top();
        q.pop();
        int DisNow = tmp.first, id = tmp.second;
        if(vis[id]) continue;
        vis[id] = 1;
        for(int i = h[id]; i; i = ne[i])
        {
            int j = e[i];
            if(dist[j] > DisNow + w[i])
            {
                dist[j] = DisNow + w[i];
                q.push({dist[j], j});
            }
        }
    }
}

    int main()
{
    R(n);
    R(m);
    R(s);
    R(t);
    for (int i = 1; i <= m; i++)
    {
        int a, b, c;
        R(a);
        R(b);
        R(c);
        add(a, b, c);
        add(b, a, c);
    }
    Dijkstra(s, t);
    printf("%d\n", dist[t]);
    system("pause");
    return 0;
}

 

标签:1129,ch,dist,int,热浪,vis,include,id
From: https://www.cnblogs.com/smartljy/p/17785309.html

相关文章

  • CF1129D Isolation
    考虑dp,令\(f_i\)为\([1,i]\)这个前缀的分段方案数。\(i\)从小到大扫描线,动态维护\(c_j\)表示\([j+1,i]\)中只出现恰好一次的数的个数:\[f_i=\sum\limits_{c_j\lek}f_j\]考虑如何维护\(c_j\),扫描线过程中维护\(l_i\)表示\(a_i\)上次出现的位置。那么\(i-1\toi\)......
  • LonLife-ACM 1129 - 喵哈哈村的战斗魔法师丶坏坏い月
    原题链接1129-喵哈哈村的战斗魔法师丶坏坏い月TimeLimit:3s MemoryLimit:256MByteSolved:85DESCRIPTION坏坏い月是月大叔的ID,他是一个掌握者772002种魔法的物理系战士,最擅长的技能就是搞事。今天他又要开始搞事了。nn个数,你需要实现一下操作:lrv,在[l,r]......
  • 【已解决】MySQL连接错误 ERROR 1129 (00000): Host ” is blocked because of many c
     问题连接MySQL 报错 ERROR1129(00000):Host”isblockedbecauseofmanyconnectionerrors原因同一个IP在短时间内产生太多终端的数据库连接(超过mysql数据库max_connection_errors设置),导致被阻塞。在系统变量:max_connect_errors设置了允许中断的次数,超过了这个次数(或者......
  • 应用连MySQL 报错ERROR 1129 Host is blocked because of many connection errors
    开发反馈应用连MySQL报错 createconnectionSQLException,url:连接串,errorCode1129。搜索1129报错,报错内容为:Hostisblockedbecauseofmanyconnectionerrors一、报错原因同一个ip在短时间内产生太多中断的数据库连接(超过mysql数据库max_connection_errors设置),导......
  • 「解题报告」CF1129D Isolation
    水题,但是调了好久qwq显然是DP,出现次数显然分块,那就数据结构优化DP呗。我们可以维护出当前点到每个点这段区间内有多少个出现次数为\(1\)的数,这个右端点每拓展一位修改的左端点一定是连续的区间。分块维护这个东西,如果是散块暴力重构暴力加,如果是整块那给整块打个加标记。......
  • UVa 11129 An antiarithmetic permutation (构造题&想法题&分治)
    11129-AnantiarithmeticpermutationTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=2070Apermutationof n+1 isabijectivefunctionoftheinitial n+1......
  • 1129.shortest-path-with-alternating-colors 颜色交替的最短路径
    问题描述1129.颜色交替的最短路径解题思路首先,将本题的图结构以边表的形式表现出来,然后采取广度优先搜索的方式寻找最短路径,一般来说广度优先搜索能够保证找到的是最短......
  • redis部署手册_20221129
    1.软件版本及下载Keepalived:https://www.keepalived.org/download.htmlRedis下载地址:https://redis.io/download/本次安装版本:Redis:7.0.5Keepalived:2.2.72.主......
  • 连接mysql报错 errorCode 1129, state HY000, Host ‘xxx‘ is blocked because of ma
    https://copyfuture.com/blogs-details/202206101947537199错误原因:mysql设定了单个客户端最大连接失败次数,超过后便无法再连接成功.可命令行查看:最大失败数为100.......
  • 云计算CloudSim20221129
    贪心调度策略原本的想法是先计算time矩阵即每个任务在每个虚拟机下运行所需的时间首先维护每个虚拟机执行已经绑定的任务所需要的总时间然后我们按任务编号的顺序循环......