zoukankan      html  css  js  c++  java
  • [OI

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <queue>
     
    using namespace std;
    //#define DEBUG(x) cerr << #x << "=" << x << endl
    const int maxn = 1e6 + 10;
    
    struct Edge
    { 
    	int v;
    	int w;
    	int nxt; 
    }e[maxn];
    
    struct node 
    {
        int u, d;
        bool operator <(const node& rhs) const 
    	{
            return d > rhs.d;
        }
    };
    
    int head[maxn], cnt = 0;
    int n, m;
    int dis[maxn];
    
    inline void addEdge(int u, int v, int w) 
    {
        e[++cnt].v = v;
        e[cnt].w = w;
        e[cnt].nxt = head[u];
        head[u] = cnt;
    }
    
    inline void Dijkstra() 
    {
        for (register int i = 1; i <= n; i++) dis[i] = 0x7fffffff;
        dis[1] = 0;
        priority_queue<node> Q;
        Q.push((node){1,0});    
        while (!Q.empty()) 
    	{
            node fr = Q.top(); 
    		Q.pop();
            int u = fr.u;
    		int d = fr.d;
            if (d != dis[u]) continue;
            for (register int i = head[u]; i; i = e[i].nxt) 
    		{
                int v = e[i].v;
    			int w = e[i].w;
                if (dis[u] + w < dis[v]) 
    			{
                    dis[v] = dis[u] + w;
                    Q.push((node){v,dis[v]});
                }
            }
        }
    }
    
    int main()  
    {
        scanf("%d%d", &n, &m);
        for (register int i = 1; i <= m; i++) 
    	{
            int x, y, z;
            scanf("%d%d%d", &x, &y, &z);
            addEdge(x, y, z);
            addEdge(y, x, z);
        }
        Dijkstra();
        printf("%d
    ", dis[n]);
        return 0;
    }
    
  • 相关阅读:
    045_List view button
    044_Schedule Job 间隔时间自动执行
    043_关于Salesforce集中权限的解释
    041_Record Type
    040_Field Set
    039_External Data Source(转载)
    037_Clone Button
    036_在salesforce中更换自定义app的logo
    020_Json的使用
    033_SFDC-Apex案例整理-未完
  • 原文地址:https://www.cnblogs.com/aiyi2000/p/9920866.html
Copyright © 2011-2022 走看看