5 条题解

  • 2
    @ 2018-10-30 18:19:27

    dijkstra+堆优化

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<cctype>
    #include<algorithm>
    #include<stack>
    #include<queue>
    #include<vector>
    #include<map>
    #define INF 2147483647
    #define LL long long
    #define ULL unsigned long long
    #define MAXN 10005
    using namespace std;
    inline int read()
    {
        char ch=getchar();
        int x=0,f=1;
        while(!isdigit(ch))
        {
            if(ch=='-') f=-1;
            ch=getchar();
        }
        while(isdigit(ch))
        {
            x=x*10+ch-'0';
            ch=getchar();
        }
        return x*f;
    }
    struct Edge{
        int v,w;
        Edge(int v=0,int w=0):v(v),w(w){}
        
    };
    struct Node{
        int id;
        LL d;
        Node(int id=0,LL d=0):id(id),d(d){}
        bool operator <(const Node& n1)const{
            return d>n1.d;
        }
    };
    vector<Edge> adj[50005];
    priority_queue<Node> q;
    int n,m,s;
    LL d[MAXN];
    bool vis[MAXN];
    void dijkstra(int st)
    {
        for(int i=1;i<=n;i++) d[i]=INF;
        d[st]=0;
        int u=0,v=0,w=0;
        q.push(Node(st,0));
        while(!q.empty())
        {
            u=q.top().id;
            q.pop();
            if(vis[u]) continue;
            vis[u]=1;   
            int len=adj[u].size();
            for(int i=0;i<len;i++)
            {
                v=adj[u][i].v;
                w=adj[u][i].w;
                if(d[u]+w<d[v])
                {
                    d[v]=d[u]+w;
                    q.push(Node(v,d[v]));
                }
            }
        }
    }
    int aa,bb,cc;
    int main()
    {
        aa=read();
        bb=read();
        cc=read();
        n=4;
        adj[1].push_back(Edge(2,aa));
        adj[2].push_back(Edge(3,bb));
        adj[3].push_back(Edge(4,cc));
        dijkstra(1);
        printf("%lld",d[4]);
        return 0;
    }
    
    
  • 1
    @ 2021-01-29 20:56:52

    #include <iostream>
    using namespace std;
    int main()
    {
    int a,b,c;
    cin>>a;
    cin>>b;
    cin>>c;
    cout<<a+b+c;
    return 0;
    }

  • 1
    @ 2020-09-05 15:29:45

    a=int(input())
    b=int(input())
    c=int(input())
    d=a+c+b
    print(d)

  • 1
    @ 2018-12-28 17:32:20

    人生苦短

    print(int(input())+int(input())+int(input()))
    
  • 1
    @ 2017-10-31 12:19:05

    a=int(input())
    b=int(input())
    c=int(input())
    print(a+b+c)

  • 1

信息

难度
1
分类
(无)
标签
(无)
递交数
692
已通过
393
通过率
57%
上传者