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

又囧了……

Posted by yc5_yc at 2012-09-02 17:09:16 on Problem 2455
原来它是无向图,原来它的重边不可合并!
#include<cstdio>
using namespace std;
const int NMax=210,PMax=40100;
struct node {
    int num,len;
    node *next,*rev;
}*A[NMax],pool[PMax*4];
int N,nn,L,P,T,F[NMax][NMax];
void Build(int x,int y,int z) {
    node *p=&pool[L++],*q=&pool[L++];
    p->num=y;p->len=z;p->next=A[x];A[x]=p;p->rev=q;
    q->num=x;q->len=0;q->next=A[y];A[y]=q;q->rev=p;
}
int level[NMax],q[NMax];
bool makelevel() {
    for(int i=1;i<=nn;i++) level[i]=-1;
    level[0]=0;q[0]=0;
    for(int i=0,bot=1;i<bot;i++) {
        int x=q[i];
        for(node *p=A[x];p;p=p->next) 
            if(p->len&&level[p->num]==-1) level[q[bot++]=p->num]=level[x]+1;
    }
    return level[nn]!=-1;
}
inline int min(int a,int b) {return a<b?a:b;}
int Find(int a,int alpha) {
    if(a==nn) return alpha;
    int tot=0,tmp;
    for(node *p=A[a];p&&tot<alpha;p=p->next) {
        if(p->len&&level[p->num]==level[a]+1) {
            if(tmp=Find(p->num,min(alpha-tot,p->len))) {
                tot+=tmp;
                p->len-=tmp;
                p->rev->len+=tmp;
            }
        }
    }
    if(!tot) level[a]=-1;
    return tot;
}
int X[PMax],Y[PMax],Z[PMax];
int main()
{
    int x,y,z,ZMax=0;
    scanf("%d%d%d",&N,&P,&T);
    for(int i=1;i<=P;i++) {
        scanf("%d%d%d",X+i,Y+i,Z+i);
        if(Z[i]>ZMax) ZMax=Z[i];
    }
    x=0;y=ZMax+10;
    nn=N;
    int ans=100000000;
    while(x<=y) {
        if(x+1==y) break;
        int mid=(x+y)>>1;
        L=0;
        for(int i=0;i<=nn;i++) A[i]=NULL;
        Build(0,1,T);
        int Maxa=0;
        for(int i=1;i<=P;i++) 
            if(Z[i]<=mid) {Build(X[i],Y[i],1);Build(Y[i],X[i],1);if(Z[i]>Maxa) Maxa=Z[i];}
        int ret=0,tmp;
        while(makelevel()) 
            while(tmp=Find(0,100000000)) ret+=tmp;
        if(ret>=T) {y=mid;if(Maxa<ans)ans=Maxa;}
        else x=mid;
    }
    printf("%d\n",ans);
    getchar();getchar();
    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