Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

最简单的Prim,125ms

Posted by bobchennan at 2010-02-22 17:36:56 on Problem 1861
void prim()
{
    int min=-INF;
    memset(dis,44,sizeof(dis));
    dis[1]=0,used[1]=true;
    for (int r=ed[1];r;r=next[r])
      dis[e[r]]=v[r],update[e[r]]=1;
    for (int i=1;i<n;i++)
    {
        int best=INF,r;
        for (int j=1;j<=n;j++)
          if (!used[j]&&dis[j]<best)
            best=dis[j],r=j;
        if (dis[r]>min)
          min=dis[r];
        used[r]=true;
        for (int j=ed[r];j;j=next[j])
          if (!used[e[j]])
            if (dis[e[j]]>v[j])
              dis[e[j]]=v[j],update[e[j]]=r;
    }
    printf("%d\n",min);
    printf("%d\n",n-1);
    for (int i=2;i<=n;i++)
      printf("%d %d\n",update[i],i);
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator