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

show show代码

Posted by shuaige123 at 2011-05-20 12:40:20 on Problem 2455
#include<stdio.h>
#include<string.h>
struct node
{
    int x,y,d;
}elist[41000];
int c[210][210],ct[210][210],map[210][210];
int n,delta;
int head,tail,pre[230],d[230], list[230];
bool v[230];
int min(int x,int y) { return x>y?y:x;}
void bfs()
{
    int i,x,y;
    memset(v,true,sizeof(v));
    head=tail=1; d[1]=50000; d[n]=-1;
    list[1]=1;v[1]=false;pre[1]=0;
    while (head<=tail)
    {
        x=list[head];
        for(i=1;i<=n;i++)
        {
           y=i;
           if(v[y]&&c[x][y]>0)
           {
              v[y]=false;
              list[++tail]=y;
              pre[y]=x;
              d[y]= min(d[x],c[x][y]);
              if(y==n) break;
           }
        }
        if(d[n]!=-1)break;
        head++;
    }
    delta=d[n];
    if(delta==-1) return ;
    x=n;
    while(pre[x]!=0)
    {
        c[pre[x]][x]-=delta;
        c[x][pre[x]]+=delta;
        x=pre[x];
    }

}
int maxflow()
{
    int ans=0;
    do{
        bfs();
        if (delta==-1) break;
        ans+=delta;
    }while(1);
    return ans;
}
int main()
{
    int p,t,x,y,d,i,j,l,r,mid,ans;

    scanf("%d%d%d",&n,&p,&t);

    memset(map,0,sizeof(map));
    r=0;
    for(i=1;i<=p;i++)
    {
        scanf("%d%d%d",&x,&y,&d);
        elist[i].x=x;   elist[i].y=y;  elist[i].d=d;
        if(r<d)r=d;
    }

    l=0;
    while(l<=r)
    {
        mid=(l+r)/2;
        memset(c,0,sizeof(c));
        for(i=1;i<=p;i++)
           if( elist[i].d<=mid)
           {
              c[elist[i].x][elist[i].y]+=1;
              c[elist[i].y][elist[i].x]+=1;
           }
        if(maxflow()>=t){ r=mid-1;  ans=mid;}
        else l=mid+1;
    }
    printf("%d\n",ans);
    return 0;
}

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