• BZOJ 1631 Cow Party


    2*spfa.

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<queue>
    #include<algorithm>
    #define maxv 1050
    #define maxe 200500
    #define inf 2000000000
    using namespace std;
    queue <int> q;
    int n,m,s,x,y,z,g[maxv],nume=0,dis[maxv][3];
    struct edge
    {
        int v,w,nxt;
    }e[maxe];
    bool vis[maxv];
    void addedge(int u,int v,int w)
    {
        e[++nume].v=v;
        e[nume].w=w;
        e[nume].nxt=g[u];
        g[u]=nume;
    }
    void spfa(int type)
    {
        for (int i=1;i<=n;i++)
        {
            dis[i][type]=inf;
            vis[i]=false;
        }
        dis[s][type]=0;vis[s]=true;q.push(s);
        while (!q.empty())
        {
            int head=q.front();q.pop();
            for (int i=g[head];i;i=e[i].nxt)
            {
                int v=e[i].v;
                 if ((i%2==type) && (dis[v][type]>dis[head][type]+e[i].w))
                {
                    dis[v][type]=dis[head][type]+e[i].w;
                    if (!vis[v]) {vis[v]=true;q.push(v);}
                }
            }
            vis[head]=false;
        }
    }
    int main()
    {
        scanf("%d%d%d",&n,&m,&s);
        for (int i=1;i<=m;i++)
        {
            scanf("%d%d%d",&x,&y,&z);
            addedge(x,y,z);addedge(y,x,z);
        }
        spfa(0);
        spfa(1);
        int ans=0;
        for (int i=1;i<=n;i++)
            ans=max(ans,dis[i][0]+dis[i][1]);
        printf("%d
    ",ans);
        return 0;
    }
  • 相关阅读:
    open-falcon实现邮件报警
    open-falcon监控Flume
    Ubuntu下安装open-falcon-v0.2.1
    Python学习笔记——发邮件
    Flume的监控参数
    Ubuntu下安装Kafka Manager
    Ubuntu系统监控indicator-sysmonitor
    kafka性能测试
    Ubuntu下安装sbt
    Ubuntu安装shadow$ocks-libev
  • 原文地址:https://www.cnblogs.com/ziliuziliu/p/5925913.html
Copyright © 2020-2023  润新知