sgu 326 Perspective(最大流)

326. Perspective
Time limit per test: 0.5 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



Breaking news! A Russian billionaire has bought a yet undisclosed NBA team. He's planning to invest huge effort and money into making that team the best. And in fact he's been very specific about the expected result: the first place.

Being his advisor, you need to determine whether it's possible for your team to finish first in its division or not.

More formally, the NBA regular season is organized as follows: all teams play some games, in each game one team wins and one team loses. Teams are grouped into divisions, some games are between the teams in the same division, and some are between the teams in different divisions.

Given the current score and the total number of remaining games for each team of your division, and the number of remaining games between each pair of teams in your division, determine if it's possible for your team to score at least as much wins as any other team in your division.

Input
The first line of input contains  N  (2 ≤  N  ≤ 20) — the number of teams in your division. They are numbered from 1 to  N , your team has number 1.

The second line of input contains  N  integers  w 1 w 2 ,...,  w N , where  w i  is the total number of games that  i th  team has won to the moment.

The third line of input contains  N  integers  r 1 r 2 ,...,  r N , where  r i  is the total number of remaining games for the  i th  team (including the games inside the division).

The next  N  lines contain  N  integers each. The  j th  integer in the  i th  line of those contains  a ij  — the number of games remaining between teams  i  and  j . It is always true that  a ij =a ji  and  a ii =0, for all  i   a i1  +  a i2  +... +  a iN  ≤  r i .

All the numbers in input are non-negative and don't exceed 10\,000.

Output
On the only line of output, print "
YES
" (without quotes) if it's possible for the team 1 to score at least as much wins as any other team of its division, and "
NO
" (without quotes) otherwise.

Example(s)
sample input
sample output
3
1 2 2
1 1 1
0 0 0
0 0 0
0 0 0
YES

sample input
sample output
3
1 2 2
1 1 1
0 0 0
0 0 1
0 1 0
NO

题目:http://acm.sgu.ru/problem.php?contest=0&problem=326

分析:这题与这题一样,就不具体分析了。。。

代码:

#include<cstdio>
#include<iostream>
using namespace std;
const int oo=1000000000;
const int mm=6666;
const int mn=1111;
int node,edge,src,dest;
int ver[mm],flow[mm],next[mm];
int head[mn],work[mn],dis[mn],q[mn],w[mn];
int t[22][22];
void prepare(int _node,int _src,int _dest)
{
    node=_node,src=_src,dest=_dest;
    for(int i=0;i<node;++i)head[i]=-1;
    edge=0;
}

void addedge(int u,int v,int c)
{
    ver[edge]=v,flow[edge]=c,next[edge]=head[u],head[u]=edge++;
    ver[edge]=u,flow[edge]=0,next[edge]=head[v],head[v]=edge++;
}
int Dinic_bfs()
{
    int i,u,v,l,r=0;
    for(i=0;i<node;++i)dis[i]=-1;
    dis[q[r++]=src]=0;
    for(l=0;l<r;++l)
        for(i=head[u=q[l]];i>=0;i=next[i])
            if(flow[i]&&dis[v=ver[i]]<0)
            {
                dis[q[r++]=v]=dis[u]+1;
                if(v==dest)return 1;
            }
    return 0;
}
int Dinic_dfs(int u,int exp)
{
    if(u==dest)return exp;
    for(int &i=work[u],v,tmp;i>=0;i=next[i])
        if(flow[i]&&dis[v=ver[i]]==dis[u]+1&&(tmp=Dinic_dfs(v,min(exp,flow[i])))>0)
        {
            flow[i]-=tmp;
            flow[i^1]+=tmp;
            return tmp;
        }
    return 0;
}
int Dinic_flow()
{
    int i,ret=0,delta;
    while(Dinic_bfs())
    {
        for(i=0;i<node;++i)work[i]=head[i];
        if(delta=Dinic_dfs(src,oo))ret+=delta;
    }
    return ret;
}
int main()
{
    int i,j,m,n,sum,r;
    while(scanf("%d",&n)!=-1)
    {
        for(i=1;i<=n;++i)scanf("%d",&w[i]);
        scanf("%d",&r);
        w[1]+=r;
        for(i=1;i<n;++i)scanf("%d",&r);
        m=0;
        for(i=1;i<=n;++i)
            for(j=1;j<=n;++j)
            {
                scanf("%d",&t[i][j]);
                if(i>1&&i<j&&t[i][j])++m;
            }
        prepare(n+m+2,0,n+m+1);
        sum=r=0;
        for(i=2;i<=n;++i)
            for(j=i+1;j<=n;++j)
                if(t[i][j])
                {
                    sum+=t[i][j];
                    ++r;
                    addedge(src,r,t[i][j]);
                    addedge(r,m+i,oo);
                    addedge(r,m+j,oo);
                }
        for(i=2;i<=n;++i)
        {
            if(w[i]>w[1])break;
            addedge(m+i,dest,w[1]-w[i]);
        }
        if(i>n&&Dinic_flow()==sum)puts("YES");
        else puts("NO");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值