sgu 326——Perspective

來源:互聯網
上載者:User
A - Perspective

Crawling in process...
Crawling failed
Time Limit:500MS    
Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Submit

Status
Practice
SGU 326

 

Description

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 w1,    
w2,...,     wN, where
wi is the total number of games that
ith team has won to the moment.    

The third line of input contains N integers r1,    
r2,...,     rN, where
ri is the total number of remaining games for the
ith team (including the games inside the division).    

The next N lines contain N integers each. The jth integer in the
ith line of those contains
aij — the number of games remaining between teams
i and j. It is always true that aij=a
ji and aii=0, for all
iai1 +     ai2 +... +    
aiN ≤     ri.    

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.

Sample Input

sample input
sample output
31 2 21 1 10 0 00 0 00 0 0
YES

sample input
sample output
31 2 21 1 10 0 00 0 10 1 0
NO

 

網路流

 

#include <iostream>#include<cstdio>#include<cstring>#include<cstdio>#include<queue>#include<vector>using namespace std;#define INF 100000001const int maxint=1000001;int n,m,s,t;int num[100],remain[100];int map[100][100];struct edgee{int from,to,cap,flow;};vector<edgee> edges;vector<int> G[10003];bool vis[10003];int dist[10003];int cur[10003];void add(int from,int to,int cap){edges.push_back((edgee){from,to,cap,0});edges.push_back((edgee){to,from,0,0});int k=edges.size();G[from].push_back(k-2);//奇數為正向弧 G[to].push_back(k-1);}int max(int a,int b){return a>b?a:b;}int min(int a,int b){return a<b?a:b;}bool bfs(){memset(vis,0,sizeof(vis));queue<int> q;dist[s]=0;vis[s]=1;q.push(s);while(!q.empty()){int u=q.front();q.pop();int sz=G[u].size();for(int i=0;i<sz;i++){edgee& e=edges[G[u][i]];if(!vis[e.to] && e.cap>e.flow){vis[e.to]=1;dist[e.to]=dist[u]+1;q.push(e.to);}}}return vis[t];}int dfs(int u,int low){if(u==t || low==0)return low;int flow=0,sz=G[u].size(),d;//&引用的妙用for(int& i=cur[u];i<sz;i++) //正在考慮的最後一條邊開始考慮(效率關鍵){edgee& e=edges[G[u][i]];if(dist[u]+1==dist[e.to] && (d=dfs(e.to,min(e.cap-e.flow,low)))>0 ){e.flow+=d;edges[G[u][i]^1].flow-=d;flow+=d;low-=d;if(low==0)break;}}return flow;}int Dinic(){int flow=0;while(bfs()){memset(cur,0,sizeof(cur));flow+=dfs(s,maxint);}return flow;}int main(){int i,j;s=4003,t=4004;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&num[i]);for(int i=1;i<=n;i++)scanf("%d",&remain[i]);for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)scanf("%d",&map[i][j]);num[1]+=remain[1];for(int i=1;i<=n;i++)if(map[1][i]!=0)map[1][i]=map[i][1]=0;for(int i=2;i<=n;i++){add(i,t,INF);if(num[1]-num[i]<0){printf("NO\n");return 0;}add(i+100,i,num[1]-num[i]);}int k=0;int sum=0;for(int i=2;i<=n;i++)for(int j=2;j<=n;j++)if(map[i][j]!=0){k++;sum+=map[i][j];add(300+k,i+100,INF);add(300+k,j+100,INF);add(s,300+k,map[i][j]);map[i][j]=map[j][i]=0;}int temp=Dinic();if(temp==sum)   printf("YES\n");elseprintf("NO\n");return 0;}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.