B - Por Costel and the Algorithm-最短路记录边

  • B - Por Costel and the Algorithm

  •  Gym - 100923B 
  • #include
    #include
    #include
    #include
    #include
    #include
    using namespace std;
    #define ll long long
    #define maxn 1000005
    #define inf 0x7fffffff
    ll head[maxn],cnt,pre[maxn];
    ll u,v,w,sum,m,n,t;
    bool vis[maxn],out[maxn];
    struct node
    {
        ll v,w,to;
    } edge[maxn];
    struct hed
    {
        ll order,w;
        bool operator<(const hed &x)const
        {
            return w>x.w;
        }
    } top,dis[maxn];
    void ad(ll u,ll v,ll w)
    {
        edge[cnt].v=v;
        edge[cnt].to=head[u];
        edge[cnt].w=w;
        head[u]=cnt;
        cnt++;
    }
    void dijst()
    {
        dis[1].w=0;
        priority_queueq;
        q.push(dis[1]);
        while(!q.empty())
        {
            top=q.top();
            q.pop();
            if(!vis[top.order])
            {
                vis[top.order]=1;
                for(int i=head[top.order]; i!=-1; i=edge[i].to)
                {
                    if(dis[edge[i].v].w>dis[top.order].w+edge[i].w)
                    {
                        dis[edge[i].v].w=dis[top.order].w+edge[i].w;
                        q.push(dis[edge[i].v]);
                        out[i]=1;
                        out[pre[edge[i].v]]=0;
                        pre[edge[i].v]=i;
                    }
                }
            }
        }
    }
    void dfs(ll u)
    {
        for(ll i=head[u]; i!=-1; i=edge[i].to)
        {
            if(out[i])
            {
                sum++;
                if(sum
  •  

你可能感兴趣的:(最短路)